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::error::Error;
15 // Read environment variables.
16 let project_name = option_env!("PROJECT_NAME").unwrap_or("bat");
17 let executable_name = option_env!("PROJECT_EXECUTABLE").unwrap_or(project_name);
18 static PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION");
20 /// Generates a file from a liquid template.
22 variables: &liquid::Object,
24 out_file: impl AsRef<Path>,
25 ) -> Result<(), Box<dyn Error>> {
26 let template = liquid::ParserBuilder::with_stdlib()
28 .parse(&fs::read_to_string(in_file)?)?;
30 fs::write(out_file, template.render(variables)?)?;
34 let variables = liquid::object!({
35 "PROJECT_NAME": project_name,
36 "PROJECT_EXECUTABLE": executable_name,
37 "PROJECT_VERSION": PROJECT_VERSION,
40 let out_dir_env = std::env::var_os("OUT_DIR").expect("OUT_DIR to be set in build.rs");
41 let out_dir = Path::new(&out_dir_env);
43 fs::create_dir_all(out_dir.join("assets/manual")).unwrap();
44 fs::create_dir_all(out_dir.join("assets/completions")).unwrap();
48 "assets/manual/bat.1.in",
49 out_dir.join("assets/manual/bat.1"),
53 "assets/completions/bat.fish.in",
54 out_dir.join("assets/completions/bat.fish"),
66// include!("src/clap_app.rs");
68// const BIN_NAME: &str = "bat";
71// let outdir = std::env::var_os("SHELL_COMPLETIONS_DIR").or(std::env::var_os("OUT_DIR"));
73// let outdir = match outdir {
75// Some(outdir) => outdir,
78// fs::create_dir_all(&outdir).unwrap();
80// let mut app = build_app(true);
81// app.gen_completions(BIN_NAME, Shell::Bash, &outdir);
82// app.gen_completions(BIN_NAME, Shell::Fish, &outdir);
83// app.gen_completions(BIN_NAME, Shell::Zsh, &outdir);
84// 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