summaryrefslogtreecommitdiffstats
path: root/assets/completions
diff options
context:
space:
mode:
authorEthan P <eth-p+git@hidden.email>2019-05-02 00:31:15 -0700
committerDavid Peter <sharkdp@users.noreply.github.com>2019-05-14 22:50:42 +0200
commit1b2066c5f286c5a4638e3d46add69732ab3d1001 (patch)
treec86eadad396df0f3ea1c11c8066ad668cb374c1d /assets/completions
parent4ec3cdb5b85d616c908b07b03b9de1a776a12c69 (diff)
Add fish shell argument completions for --language option
Diffstat (limited to 'assets/completions')
-rw-r--r--assets/completions/bat.fish38
1 files changed, 34 insertions, 4 deletions
diff --git a/assets/completions/bat.fish b/assets/completions/bat.fish
index 66bb5592..b09f8087 100644
--- a/assets/completions/bat.fish
+++ b/assets/completions/bat.fish
@@ -1,7 +1,39 @@
# Fish Shell Completions
-
# Place or symlink to $XDG_CONFIG_HOME/fish/completions/bat.fish ($XDG_CONFIG_HOME is usually set to ~/.config)
+# Helper function:
+function __bat_autocomplete_languages --description "A helper function used by "(status filename)
+ bat --list-languages | awk '
+ NR == 1 {
+ dc = 0;
+ while (substr($0, dc, 2) != " ") dc++;
+ while (substr($0, dc, 1) == " ") dc++;
+ }
+
+ {
+ langField = substr($0, 0, dc - 2);
+ if (langField !~ /^ *$/) {
+ lang = langField;
+ sub(/ +$/, "", lang);
+ }
+
+ split(substr($0, dc), exts, ",");
+ for (i in exts) {
+ ext = exts[i]
+
+ sub(/^ +/, "", ext); # Trim leading whitespace.
+ sub(/ +$/, "", ext); # Trim trailing whitespace.
+
+ if (ext != "") {
+ print ext"\t"lang
+ }
+ }
+ }
+ ' | sort
+end
+
+# Completions:
+
complete -c bat -l color -xka "auto never always" -d "Specify when to use colored output (default: auto)" -n "not __fish_seen_subcommand_from cache"
complete -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
complete -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"
-# TODO: add parameter completion for available languages using option: -xka "(bat --list-languages | cat)"
-# but replace 'cat' with some sed/awk like command that only outputs lines of valid options for this flag
-complete -c bat -s l -l language -d "Set the language for syntax highlighting" -n "not __fish_seen_subcommand_from cache"
+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)"
complete -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"