@@ -1,7 +1,39 @@
1# Fish Shell Completions
1# Fish Shell Completions
3# Place or symlink to $XDG_CONFIG_HOME/fish/completions/bat.fish ($XDG_CONFIG_HOME is usually set to ~/.config)
2# Place or symlink to $XDG_CONFIG_HOME/fish/completions/bat.fish ($XDG_CONFIG_HOME is usually set to ~/.config)
5+function __bat_autocomplete_languages --description "A helper function used by "(status filename)
6+ bat --list-languages | awk '
9+ while (substr($0, dc, 2) != " ") dc++;
10+ while (substr($0, dc, 1) == " ") dc++;
14+ langField = substr($0, 0, dc - 2);
15+ if (langField !~ /^ *$/) {
17+ sub(/ +$/, "", lang);
20+ split(substr($0, dc), exts, ",");
24+ sub(/^ +/, "", ext); # Trim leading whitespace.
25+ sub(/ +$/, "", ext); # Trim trailing whitespace.
5complete -c bat -l color -xka "auto never always" -d "Specify when to use colored output (default: auto)" -n "not __fish_seen_subcommand_from cache"
37complete -c bat -l color -xka "auto never always" -d "Specify when to use colored output (default: auto)" -n "not __fish_seen_subcommand_from cache"
7complete -c bat -l config-dir -d "Display location of 'bat' configuration directory" -n "not __fish_seen_subcommand_from cache"
39complete -c bat -l config-dir -d "Display location of 'bat' configuration directory" -n "not __fish_seen_subcommand_from cache"
@@ -16,9 +48,7 @@ complete -c bat -s H -l highlight-line -x -d "<N> Highlight the N-th line with a
17complete -c bat -l italic-text -xka "always never" -d "Specify when to use ANSI sequences for italic text (default: never)" -n "not __fish_seen_subcommand_from cache"
49complete -c bat -l italic-text -xka "always never" -d "Specify when to use ANSI sequences for italic text (default: never)" -n "not __fish_seen_subcommand_from cache"
19−# TODO: add parameter completion for available languages using option: -xka "(bat --list-languages | cat)"
20−# but replace 'cat' with some sed/awk like command that only outputs lines of valid options for this flag
21−complete -c bat -s l -l language -d "Set the language for syntax highlighting" -n "not __fish_seen_subcommand_from cache"
51+complete -c bat -s l -l language -d "Set the language for syntax highlighting" -n "not __fish_seen_subcommand_from cache" -xa "(__bat_autocomplete_languages)"
23complete -c bat -s r -l line-range -x -d "<N:M> Only print the specified range of lines for each file" -n "not __fish_seen_subcommand_from cache"
53complete -c bat -s r -l line-range -x -d "<N:M> Only print the specified range of lines for each file" -n "not __fish_seen_subcommand_from cache"