Browse Source

Add zsh and fish completion wrt #19

tags/v0.1.5-alpha4
Julian Ospald 4 years ago
parent
commit
640cf1e2c1
No known key found for this signature in database GPG Key ID: 511B62C09D50CD28
3 changed files with 51 additions and 0 deletions
  1. +0
    -0
      shell-completions/bash
  2. +19
    -0
      shell-completions/fish
  3. +32
    -0
      shell-completions/zsh

.bash-completion → shell-completions/bash View File


+ 19
- 0
shell-completions/fish View File

@@ -0,0 +1,19 @@
function _ghcup
set -l cl (commandline --tokenize --current-process)
# Hack around fish issue #3934
set -l cn (commandline --tokenize --cut-at-cursor --current-process)
set -l cn (count $cn)
set -l tmpline --bash-completion-enriched --bash-completion-index $cn
for arg in $cl
set tmpline $tmpline --bash-completion-word $arg
end
for opt in (ghcup $tmpline)
if test -d $opt
echo -E "$opt/"
else
echo -E "$opt"
end
end
end

complete --no-files --command ghcup --arguments '(_ghcup)'

+ 32
- 0
shell-completions/zsh View File

@@ -0,0 +1,32 @@
#compdef ghcup

local request
local completions
local word
local index=$((CURRENT - 1))

request=(--bash-completion-enriched --bash-completion-index $index)
for arg in ${words[@]}; do
request=(${request[@]} --bash-completion-word $arg)
done

IFS=$'\n' completions=($( ghcup "${request[@]}" ))

for word in $completions; do
local -a parts

# Split the line at a tab if there is one.
IFS=$'\t' parts=($( echo $word ))

if [[ -n $parts[2] ]]; then
if [[ $word[1] == "-" ]]; then
local desc=("$parts[1] ($parts[2])")
compadd -d desc -- $parts[1]
else
local desc=($(print -f "%-019s -- %s" $parts[1] $parts[2]))
compadd -l -d desc -- $parts[1]
fi
else
compadd -f -- $word
fi
done

Loading…
Cancel
Save