11pub fn config_file() -> PathBuf {
12 env::var("BAT_CONFIG_PATH")
15 .filter(|config_path| config_path.is_file())
16 .unwrap_or(PROJECT_DIRS.config_dir().join("config"))
19pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseError> {
21 fs::read_to_string(config_file())
23 .map(|content| get_args_from_str(&content)),
28pub fn get_args_from_env_var() -> Option<Result<Vec<OsString>, shell_words::ParseError>> {
29 env::var("BAT_OPTS").ok().map(|s| get_args_from_str(&s))
32fn get_args_from_str<'a>(content: &'a str) -> Result<Vec<OsString>, shell_words::ParseError> {
33 let args_per_line = content
35 .map(|line| line.trim())
36 .filter(|line| !line.is_empty())
37 .filter(|line| !line.starts_with("#"))
38 .map(|line| shell_words::split(line))
39 .collect::<Result<Vec<_>, _>>()?;
44 .map(|line| line.into())
50 let args = get_args_from_str("").unwrap();
51 assert!(args.is_empty());
56 assert_eq!(vec!["--plain"], get_args_from_str("--plain").unwrap());
62 vec!["--plain", "--language=cpp"],
63 get_args_from_str("--plain --language=cpp").unwrap()
70 vec!["--theme", "Sublime Snazzy"],
71 get_args_from_str("--theme \"Sublime Snazzy\"").unwrap()
79 --style numbers,changes
84 vec!["-p", "--style", "numbers,changes", "--color=always"],
85 get_args_from_str(config).unwrap()
95 # show line numbers and Git modifications
96 --style numbers,changes
98 # Always show ANSI colors
102 vec!["-p", "--style", "numbers,changes", "--color=always"],
103 get_args_from_str(config).unwrap()
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