mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-28 08:02:28 +01:00
Compare commits
1 Commits
ignore_inv
...
completion
Author | SHA1 | Date | |
---|---|---|---|
|
c4a7d888b7 |
@@ -21,6 +21,7 @@
|
||||
- Make --map-syntax target case insensitive to match --language, see #3206 (@keith-hall)
|
||||
- Correctly determine the end of the line in UTF16LE/BE input #3369 (@keith-hall)
|
||||
- `--style=changes` no longer prints a two-space indent when the file is unmodified, see issue #2710 and PR #3406 (@jyn514)
|
||||
- Add missing shell completions, see #3411 (@keith-hall)
|
||||
|
||||
## Other
|
||||
|
||||
|
22
assets/completions/bat.bash.in
vendored
22
assets/completions/bat.bash.in
vendored
@@ -80,6 +80,7 @@ _bat() {
|
||||
--line-range | \
|
||||
-L | --list-languages | \
|
||||
--lessopen | \
|
||||
--no-paging | \
|
||||
--diagnostic | \
|
||||
--acknowledgements | \
|
||||
-h | --help | \
|
||||
@@ -100,6 +101,22 @@ _bat() {
|
||||
COMPREPLY=($(compgen -W "auto never character" -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
--binary)
|
||||
COMPREPLY=($(compgen -W "no-printing as-text" -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
--nonprintable-notation)
|
||||
COMPREPLY=($(compgen -W "unicode caret" -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
--strip-ansi)
|
||||
COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
--completion)
|
||||
COMPREPLY=($(compgen -W "bash fish zsh ps1" -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
--color | --decorations | --paging)
|
||||
COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
|
||||
return 0
|
||||
@@ -157,6 +174,8 @@ _bat() {
|
||||
# --unbuffered excluded intentionally (no-op)
|
||||
COMPREPLY=($(compgen -W "
|
||||
--show-all
|
||||
--nonprintable-notation
|
||||
--binary
|
||||
--plain
|
||||
--language
|
||||
--highlight-line
|
||||
@@ -173,6 +192,7 @@ _bat() {
|
||||
--decorations
|
||||
--force-colorization
|
||||
--paging
|
||||
--no-paging
|
||||
--pager
|
||||
--map-syntax
|
||||
--ignored-suffix
|
||||
@@ -182,10 +202,12 @@ _bat() {
|
||||
--list-themes
|
||||
--squeeze-blank
|
||||
--squeeze-limit
|
||||
--strip-ansi
|
||||
--style
|
||||
--line-range
|
||||
--list-languages
|
||||
--lessopen
|
||||
--completion
|
||||
--diagnostic
|
||||
--acknowledgements
|
||||
--set-terminal-title
|
||||
|
26
assets/completions/bat.fish.in
vendored
26
assets/completions/bat.fish.in
vendored
@@ -142,10 +142,16 @@ set -l special_themes '
|
||||
|
||||
complete -c $bat -l acknowledgements -d "Print acknowledgements" -n __fish_is_first_arg
|
||||
|
||||
complete -c $bat -l binary -x -a "no-printing as-text" -d "How to treat binary content" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l cache-dir -f -d "Show bat's cache directory" -n __fish_is_first_arg
|
||||
|
||||
complete -c $bat -s c -l chop-long-lines -d "Truncate all lines longer than screen width" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l color -x -a "$color_opts" -d "When to use colored output" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l completion -x -a "bash fish zsh ps1" -d "Show shell completion for a certain shell" -n __fish_is_first_arg
|
||||
|
||||
complete -c $bat -l config-dir -f -d "Display location of configuration directory" -n __fish_is_first_arg
|
||||
|
||||
complete -c $bat -l config-file -f -d "Display location of configuration file" -n __fish_is_first_arg
|
||||
@@ -192,20 +198,34 @@ complete -c $bat -l no-custom-assets -d "Do not load custom assets"
|
||||
|
||||
complete -c $bat -l no-lessopen -d "Disable the $LESSOPEN preprocessor if enabled (overrides --lessopen)"
|
||||
|
||||
complete -c $bat -l nonprintable-notation -x -a "unicode caret" -d "Set notation for non-printable characters" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s n -l number -d "Only show line numbers, no other decorations" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l no-paging -d "Alias for --paging=never" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l pager -x -a "$pager_opts" -d "Which pager to use" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l paging -x -a "$paging_opts" -d "When to use the pager" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s p -l plain -d "Show plain style" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l set-terminal-title -d "Sets terminal title to filenames when using a pager" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s A -l show-all -d "Show non-printable characters" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s s -l squeeze-blank -d "Squeeze consecutive empty lines into a single empty line" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l squeeze-limit -x -d "Set the maximum number of consecutive empty lines to be printed" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l strip-ansi -x -a "auto never always" -d "Specify when to strip ANSI escape sequences from the input" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s p -l plain -d "Disable decorations" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -o pp -d "Disable decorations and paging" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s P -d "Disable paging" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s A -l show-all -d "Show non-printable characters" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l style -x -k -a "(__fish_complete_list , __bat_style_opts)" -d "Specify which non-content elements to display" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l tabs -x -a "$tabs_opts" -d "Set tab width" -n __bat_no_excl_args
|
||||
@@ -218,6 +238,8 @@ complete -c $bat -l theme-dark -x -a "(command $bat --list-themes | command cat)
|
||||
|
||||
complete -c $bat -l theme-light -x -a "(command $bat --list-themes | command cat)" -d "Set the syntax highlighting theme for light backgrounds" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s u -l unbuffered -d "This option exists for POSIX-compliance reasons" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s V -l version -f -d "Show version information" -n __fish_is_first_arg
|
||||
|
||||
complete -c $bat -l wrap -x -a "$wrap_opts" -d "Text-wrapping mode" -n __bat_no_excl_args
|
||||
|
12
assets/completions/bat.zsh.in
vendored
12
assets/completions/bat.zsh.in
vendored
@@ -26,6 +26,7 @@ _{{PROJECT_EXECUTABLE}}_main() {
|
||||
args=(
|
||||
'(-A --show-all)'{-A,--show-all}'[show non-printable characters (space, tab, newline, ..)]'
|
||||
--nonprintable-notation='[specify how to display non-printable characters when using --show-all]:notation:(caret unicode)'
|
||||
--binary='[specify how to treat binary content]:behavior:(no-printing as-text)'
|
||||
\*{-p,--plain}'[show plain style (alias for `--style=plain`), repeat twice to disable automatic paging (alias for `--paging=never`)]'
|
||||
'(-l --language)'{-l+,--language=}'[set the language for syntax highlighting]:language:->languages'
|
||||
\*{-H+,--highlight-line=}'[highlight specified block of lines]:start\:end'
|
||||
@@ -40,16 +41,27 @@ _{{PROJECT_EXECUTABLE}}_main() {
|
||||
--color='[specify when to use colors]:when:(auto never always)'
|
||||
--italic-text='[use italics in output]:when:(always never)'
|
||||
--decorations='[specify when to show the decorations]:when:(auto never always)'
|
||||
'(-f --force-colorization)'--force-colorization'[force colorization and decorations]'
|
||||
--paging='[specify when to use the pager]:when:(auto never always)'
|
||||
'(-P --no-paging)'--no-paging'[alias for --paging=never]'
|
||||
--pager='[determine which pager to use]:command:'
|
||||
'(-m --map-syntax)'{-m+,--map-syntax=}'[map a glob pattern to an existing syntax name]: :->syntax-maps'
|
||||
--ignored-suffix='[ignore extension]:suffix:'
|
||||
'(--theme)'--theme='[set the color theme for syntax highlighting]:theme:->theme_preferences'
|
||||
'(--theme-dark)'--theme-dark='[set the color theme for syntax highlighting for dark backgrounds]:theme:->themes'
|
||||
'(--theme-light)'--theme-light='[set the color theme for syntax highlighting for light backgrounds]:theme:->themes'
|
||||
'(: --list-themes --list-languages -L)'--list-themes'[show all supported highlighting themes]'
|
||||
--squeeze-blank'[squeeze consecutive empty lines into a single empty line]'
|
||||
--squeeze-limit='[set the maximum number of consecutive empty lines]:limit:'
|
||||
--strip-ansi='[specify when to strip ANSI escape sequences]:when:(auto never always)'
|
||||
--style='[comma-separated list of style elements to display]: : _values "style [default]"
|
||||
default auto full plain changes header header-filename header-filesize grid rule numbers snip'
|
||||
\*{-r+,--line-range=}'[only print the specified line range]:start\:end'
|
||||
'(* -)'{-L,--list-languages}'[display all supported languages]'
|
||||
'(-u --unbuffered)'--unbuffered'[this option exists for POSIX-compliance reasons]'
|
||||
--completion='[show shell completion for a certain shell]:shell:(bash fish zsh ps1)'
|
||||
--set-terminal-title'[sets terminal title to filenames when using a pager]'
|
||||
--diagnostic'[show diagnostic information for bug reports]'
|
||||
-P'[disable paging]'
|
||||
"--no-config[don't use the configuration file]"
|
||||
"--no-custom-assets[don't load custom assets]"
|
||||
|
2
assets/syntaxes/02_Extra/Jsonnet
vendored
2
assets/syntaxes/02_Extra/Jsonnet
vendored
Submodule assets/syntaxes/02_Extra/Jsonnet updated: 56ac0e6854...e2c917ed7d
2
assets/syntaxes/02_Extra/VimL
vendored
2
assets/syntaxes/02_Extra/VimL
vendored
Submodule assets/syntaxes/02_Extra/VimL updated: fe5bf5ea70...ee85822cbe
@@ -57,30 +57,15 @@ impl App {
|
||||
}
|
||||
|
||||
fn matches(interactive_output: bool) -> Result<ArgMatches> {
|
||||
// Check if we should skip config file processing for special arguments
|
||||
// that don't require full application setup (help, version, diagnostic)
|
||||
let should_skip_config = wild::args_os().any(|arg| {
|
||||
matches!(
|
||||
arg.to_str(),
|
||||
Some("-h" | "--help" | "-V" | "--version" | "--diagnostic" | "--diagnostics")
|
||||
)
|
||||
});
|
||||
|
||||
let args = if wild::args_os().nth(1) == Some("cache".into()) {
|
||||
// Skip the config file and env vars
|
||||
|
||||
wild::args_os().collect::<Vec<_>>()
|
||||
} else if wild::args_os().any(|arg| arg == "--no-config") || should_skip_config {
|
||||
// Skip the arguments in bats config file when --no-config is present
|
||||
// or when user requests help, version, or diagnostic information
|
||||
} else if wild::args_os().any(|arg| arg == "--no-config") {
|
||||
// Skip the arguments in bats config file
|
||||
|
||||
let mut cli_args = wild::args_os();
|
||||
let mut args = if should_skip_config {
|
||||
// For special commands, don't even try to load env vars that might fail
|
||||
vec![]
|
||||
} else {
|
||||
get_args_from_env_vars()
|
||||
};
|
||||
let mut args = get_args_from_env_vars();
|
||||
|
||||
// Put the zero-th CLI argument (program name) first
|
||||
args.insert(0, cli_args.next().unwrap());
|
||||
|
@@ -1286,83 +1286,6 @@ fn diagnostic_sanity_check() {
|
||||
.stderr("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_works_with_invalid_config() {
|
||||
let tmp_dir = tempdir().expect("can create temporary directory");
|
||||
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
|
||||
|
||||
// Write an invalid config file
|
||||
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
|
||||
|
||||
// --help should work despite invalid config
|
||||
bat_with_config()
|
||||
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
|
||||
.arg("--help")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains(
|
||||
"A cat(1) clone with syntax highlighting",
|
||||
));
|
||||
|
||||
// -h should also work
|
||||
bat_with_config()
|
||||
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
|
||||
.arg("-h")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("A cat(1) clone with wings"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_works_with_invalid_config() {
|
||||
let tmp_dir = tempdir().expect("can create temporary directory");
|
||||
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
|
||||
|
||||
// Write an invalid config file
|
||||
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
|
||||
|
||||
// --version should work despite invalid config
|
||||
bat_with_config()
|
||||
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
|
||||
.arg("--version")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("bat "));
|
||||
|
||||
// -V should also work
|
||||
bat_with_config()
|
||||
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
|
||||
.arg("-V")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("bat "));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diagnostic_works_with_invalid_config() {
|
||||
let tmp_dir = tempdir().expect("can create temporary directory");
|
||||
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
|
||||
|
||||
// Write an invalid config file
|
||||
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
|
||||
|
||||
// --diagnostic should work despite invalid config
|
||||
bat_with_config()
|
||||
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
|
||||
.arg("--diagnostic")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("#### Software version"));
|
||||
|
||||
// --diagnostics (alias) should also work
|
||||
bat_with_config()
|
||||
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
|
||||
.arg("--diagnostics")
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains("#### Software version"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_location_test() {
|
||||
bat_with_config()
|
||||
|
Reference in New Issue
Block a user