summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdmund Rosewright <edmundrosewright@gmail.com>2022-06-25 18:45:18 +0000
committerDerek Taylor <derek@distrotube.com>2022-06-25 18:45:18 +0000
commit3cb67f5989139b2cdac24e9211837e4bca4288cb (patch)
treef0dd0b2ff2339b06cf9e1df322b2d310ed2a3b86
parentMerge branch 'master' into 'master' (diff)
Add fish shell completions
-rw-r--r--README.md7
-rw-r--r--completions/_colorscript (renamed from zsh_completion/_colorscript)0
-rw-r--r--completions/colorscript.fish78
3 files changed, 83 insertions, 2 deletions
diff --git a/README.md b/README.md
index f6f83e7..6d5ace7 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Alternately, you could also install shell-color-scripts from the AUR using an AU
yay -S shell-color-scripts
-# Installing shell-color-scripts on other Linux distrtibutions
+# Installing shell-color-scripts on other Linux distributions
Download the source code from this repository or use a git clone:
@@ -31,7 +31,10 @@ Download the source code from this repository or use a git clone:
sudo make uninstall
# optional for zsh completion
- sudo cp zsh_completion/_colorscript /usr/share/zsh/site-functions
+ sudo cp completions/_colorscript /usr/share/zsh/site-functions
+
+ # optional for fish shell completion
+ sudo cp completions/colorscript.fish /usr/share/fish/vendor_completions.d
# Usage
diff --git a/zsh_completion/_colorscript b/completions/_colorscript
index 0912461..0912461 100644
--- a/zsh_completion/_colorscript
+++ b/completions/_colorscript
diff --git a/completions/colorscript.fish b/completions/colorscript.fish
new file mode 100644
index 0000000..f6abc7d
--- /dev/null
+++ b/completions/colorscript.fish
@@ -0,0 +1,78 @@
+# Completions for fish shell
+# This file should go in /usr/share/fish/vendor_completions.d
+# according to https://fishshell.com/docs/current/completions.html
+# function
+
+set dir_colorscripts "/opt/shell-color-scripts/colorscripts"
+set dir_blacklisted_colorscripts "$dir_colorscripts/blacklisted"
+
+# Lists all filenames in a given directory
+function list_filenames
+ set dir $argv[1]
+ if command -q find
+ # use find if available
+ set files (command find $dir -maxdepth 1 -type f)
+ else if command -q ls
+ # use ls if available
+ set files (command ls $dir)
+ else
+ # cannot provide coloscript name autocompletions for args of exec, blacklist, and unblacklist
+ return
+ end
+
+ for file in $files
+ echo (basename $file)
+ end
+end
+
+# List all colorscript names
+function cs_names
+ echo (list_filenames $dir_colorscripts | string collect)
+end
+
+# List all blacklisted colorscript names
+function blacklisted_cs_names
+ echo (list_filenames $dir_blacklisted_colorscripts | string collect)
+end
+
+# Description text
+set -l help_desc 'Print help'
+set -l list_desc 'List all installed color scripts'
+set -l random_desc 'Run a random color script'
+set -l exec_desc 'Run a specified color script by SCRIPT NAME or INDEX'
+set -l blacklist_desc 'Blacklist a color script by SCRIPT NAME or INDEX'
+set -l unblacklist_desc 'Unblacklist a color script by SCRIPT NAME or INDEX'
+set -l all_desc 'List the outputs of all colorscripts with their SCRIPT NAME'
+
+# List of all available commands and flag-style commands
+set -l commands -h --help help -l --list list -r --random random -e --exec exec \
+ -b --blacklist blacklist -u --unblacklist unblacklist -a --all all
+
+# turn off built-in file completions
+complete -c colorscript -f
+
+# Commands autocompletions
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -a help -d "$help_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -a list -d "$list_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -a random -d "$random_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -a exec -d "$exec_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -a blacklist -d "$blacklist_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -a unblacklist -d "$unblacklist_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -a all -d "$all_desc"
+
+# Flag-style commands autocompletions
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -s h -l help -d "$help_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -s l -l list -d "$list_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -s r -l random -d "$random_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -s e -l exec -d "$exec_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -s b -l blacklist -d "$blacklist_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -s u -l unblacklist -d "$unblacklist_desc"
+complete -c colorscript -n "not __fish_seen_subcommand_from $commands" -s a -l all -d "$all_desc"
+
+# Coloscript name autocompletions
+set -l commands_that_take_names -e --exec exec -b --blacklist blacklist
+complete -c colorscript -n "__fish_seen_subcommand_from $commands_that_take_names" -a '(cs_names)'
+
+# Blacklisted colorscript name autocompletions
+set -l commands_that_take_blacklisted_names -u --unblacklist unblacklist
+complete -c colorscript -n "__fish_seen_subcommand_from $commands_that_take_blacklisted_names" -a '(blacklisted_cs_names)' \ No newline at end of file