Add script to list completions available for instlled commands
This commit is contained in:
parent
d226ac7097
commit
ad5dc95e4d
22
list-commands-with-available-completions.zsh
Executable file
22
list-commands-with-available-completions.zsh
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
|
# Loop over available completions and add existing commands to array.
|
||||||
|
local -a completions
|
||||||
|
completions=(~/.config/zsh/zsh-completions/src/*)
|
||||||
|
local -a command_list
|
||||||
|
for completion in $completions; do
|
||||||
|
local filename=$(basename $completion)
|
||||||
|
local name=${filename:1}
|
||||||
|
if command -v $name &> /dev/null; then
|
||||||
|
command_list+=($name)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Print JSON array of commands Ansible can consume.
|
||||||
|
echo '['
|
||||||
|
local length=${#command_list[@]}
|
||||||
|
for (( i = 1; i < $length; i++ )); do
|
||||||
|
echo " \"${command_list[$i]}\","
|
||||||
|
done
|
||||||
|
echo " \"${command_list[-1]}\""
|
||||||
|
echo ']'
|
@ -1,19 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
# Check if third party completions are present.
|
|
||||||
local zsh_completions=~/.config/zsh/zsh-completions
|
|
||||||
[ ! -d $zsh_completions ] && return 0
|
|
||||||
|
|
||||||
# Loop over all completions.
|
|
||||||
for completion in $zsh_completions/src/_*; do
|
|
||||||
local name=`basename $completion`
|
|
||||||
local symlink=~/.local/share/zsh/site-functions/$name
|
|
||||||
# Remove existing completion file if it exists.
|
|
||||||
[ -f $symlink ] && rm $symlink
|
|
||||||
# Check if the command exists on the PATH.
|
|
||||||
if command -v ${name:1} &> /dev/null; then
|
|
||||||
# Symlink the completion for the existing command.
|
|
||||||
[ `uname` = Darwin ] && \
|
|
||||||
ln -s $completion $symlink || ln -sr $completion $symlink
|
|
||||||
fi
|
|
||||||
done
|
|
Loading…
x
Reference in New Issue
Block a user