Add zsh and fish completion wrt #19
This commit is contained in:
		
							parent
							
								
									56c439d716
								
							
						
					
					
						commit
						640cf1e2c1
					
				
							
								
								
									
										19
									
								
								shell-completions/fish
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								shell-completions/fish
									
									
									
									
									
										Normal 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
									
								
								shell-completions/zsh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								shell-completions/zsh
									
									
									
									
									
										Normal 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…
	
		Reference in New Issue
	
	Block a user