1// TODO: Re-enable generation of shell completion files (below) when clap 3 is out.
2// For more details, see https://github.com/sharkdp/bat/issues/372
4// For bat-as-a-library, no build script is required. The build script is for
5// the manpage and completions, which are only relevant to the bat application.
6#[cfg(not(feature = "application"))]
9#[cfg(feature = "application")]
10fn main() -> Result<(), Box<dyn std::error::Error>> {
11 use std::collections::HashMap;
12 use std::error::Error;
16 // Read environment variables.
17 let project_name = option_env!("PROJECT_NAME").unwrap_or("bat");
18 let executable_name = option_env!("PROJECT_EXECUTABLE").unwrap_or(project_name);
19 let executable_name_uppercase = executable_name.to_uppercase();
20 static PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION");
22 /// Generates a file from a template.
24 variables: &HashMap<&str, &str>,
26 out_file: impl AsRef<Path>,
27 ) -> Result<(), Box<dyn Error>> {
28 let mut content = fs::read_to_string(in_file)?;
30 for (variable_name, value) in variables {
31 // Replace {{variable_name}} by the value
32 let pattern = format!("{{{{{variable_name}}}}}", variable_name = variable_name);
33 content = content.replace(&pattern, value);
36 fs::write(out_file, content)?;
40 let mut variables = HashMap::new();
41 variables.insert("PROJECT_NAME", project_name);
42 variables.insert("PROJECT_EXECUTABLE", executable_name);
43 variables.insert("PROJECT_EXECUTABLE_UPPERCASE", &executable_name_uppercase);
44 variables.insert("PROJECT_VERSION", PROJECT_VERSION);
46 let out_dir_env = std::env::var_os("OUT_DIR").expect("OUT_DIR to be set in build.rs");
47 let out_dir = Path::new(&out_dir_env);
49 fs::create_dir_all(out_dir.join("assets/manual")).unwrap();
50 fs::create_dir_all(out_dir.join("assets/completions")).unwrap();
54 "assets/manual/bat.1.in",
55 out_dir.join("assets/manual/bat.1"),
59 "assets/completions/bat.bash.in",
60 out_dir.join("assets/completions/bat.bash"),
64 "assets/completions/bat.fish.in",
65 out_dir.join("assets/completions/bat.fish"),
69 "assets/completions/_bat.ps1.in",
70 out_dir.join("assets/completions/_bat.ps1"),
74 "assets/completions/bat.zsh.in",
75 out_dir.join("assets/completions/bat.zsh"),
87// include!("src/clap_app.rs");
89// const BIN_NAME: &str = "bat";
92// let outdir = std::env::var_os("SHELL_COMPLETIONS_DIR").or(std::env::var_os("OUT_DIR"));
94// let outdir = match outdir {
96// Some(outdir) => outdir,
99// fs::create_dir_all(&outdir).unwrap();
101// let mut app = build_app(true);
102// app.gen_completions(BIN_NAME, Shell::Bash, &outdir);
103// app.gen_completions(BIN_NAME, Shell::Fish, &outdir);
104// app.gen_completions(BIN_NAME, Shell::Zsh, &outdir);
105// app.gen_completions(BIN_NAME, Shell::PowerShell, &outdir);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list