on master help sign in
Add fish shell argument completions for --language option
commit1b2066c5f286c5a4638e3d46add69732ab3d1001 authorEthan P <eth-p+git@hidden.email> dateThu 2 May 2019, 00:31 (8 years ago) parent4ec3cdb
1 file changed+34−4
assets/completions/bat.fish+34−4
assets/completions/bat.fish+34−4
@@ -1,7 +1,39 @@
11# Fish Shell Completions
2−
32# Place or symlink to $XDG_CONFIG_HOME/fish/completions/bat.fish ($XDG_CONFIG_HOME is usually set to ~/.config)
43
4+# Helper function:
5+function __bat_autocomplete_languages --description "A helper function used by "(status filename)
6+ bat --list-languages | awk '
7+ NR == 1 {
8+ dc = 0;
9+ while (substr($0, dc, 2) != " ") dc++;
10+ while (substr($0, dc, 1) == " ") dc++;
11+ }
12+
13+ {
14+ langField = substr($0, 0, dc - 2);
15+ if (langField !~ /^ *$/) {
16+ lang = langField;
17+ sub(/ +$/, "", lang);
18+ }
19+
20+ split(substr($0, dc), exts, ",");
21+ for (i in exts) {
22+ ext = exts[i]
23+
24+ sub(/^ +/, "", ext); # Trim leading whitespace.
25+ sub(/ +$/, "", ext); # Trim trailing whitespace.
26+
27+ if (ext != "") {
28+ print ext"\t"lang
29+ }
30+ }
31+ }
32+ ' | sort
33+end
34+
35+# Completions:
36+
537complete -c bat -l color -xka "auto never always" -d "Specify when to use colored output (default: auto)" -n "not __fish_seen_subcommand_from cache"
638
739complete -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
1648
1749complete -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"
1850
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)"
2252
2353complete -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"
2454