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 use lazy_static::lazy_static;
17 // Read environment variables.
19 static ref PROJECT_NAME: &'static str = option_env!("PROJECT_NAME").unwrap_or("bat");
20 static ref PROJECT_VERSION: &'static str = option_env!("CARGO_PKG_VERSION").unwrap();
21 static ref EXECUTABLE_NAME: &'static str = option_env!("PROJECT_EXECUTABLE")
22 .or(option_env!("PROJECT_NAME"))
26 /// Generates a file from a liquid template.
28 variables: &liquid::Object,
30 out_file: impl AsRef<Path>,
31 ) -> Result<(), Box<dyn Error>> {
32 let template = liquid::ParserBuilder::with_stdlib()
34 .parse(&fs::read_to_string(in_file)?)?;
36 fs::write(out_file, template.render(variables)?)?;
40 let variables = liquid::object!({
41 "PROJECT_NAME": PROJECT_NAME.to_owned(),
42 "PROJECT_EXECUTABLE": EXECUTABLE_NAME.to_owned(),
43 "PROJECT_VERSION": PROJECT_VERSION.to_owned(),
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 std::fs::create_dir_all(out_dir.join("assets/manual")).unwrap();
50 std::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.fish.in",
60 out_dir.join("assets/completions/bat.fish"),
72// include!("src/clap_app.rs");
74// const BIN_NAME: &str = "bat";
77// let outdir = std::env::var_os("SHELL_COMPLETIONS_DIR").or(std::env::var_os("OUT_DIR"));
79// let outdir = match outdir {
81// Some(outdir) => outdir,
84// fs::create_dir_all(&outdir).unwrap();
86// let mut app = build_app(true);
87// app.gen_completions(BIN_NAME, Shell::Bash, &outdir);
88// app.gen_completions(BIN_NAME, Shell::Fish, &outdir);
89// app.gen_completions(BIN_NAME, Shell::Zsh, &outdir);
90// 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