2022-01-15 19:00:35 +09:00
|
|
|
|
#! bash oh-my-bash.module
|
2017-10-10 18:07:01 +07:00
|
|
|
|
# Bash completion script for homesick
|
|
|
|
|
#
|
|
|
|
|
# The homebrew bash completion script was used as inspiration.
|
|
|
|
|
# Originally from https://github.com/liborw/homesick-completion
|
2023-10-01 03:40:52 +09:00
|
|
|
|
# https://github.com/liborw/homesick-completion/blob/904d121d1b8f81629f473915a10c9144fdd416dc/homesick_bash_completion.sh
|
2017-10-10 18:07:01 +07:00
|
|
|
|
|
2023-10-01 03:19:46 +09:00
|
|
|
|
_omb_completion_homesick()
|
2017-10-10 18:07:01 +07:00
|
|
|
|
{
|
2023-10-01 03:40:52 +09:00
|
|
|
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
2023-10-01 03:32:03 +09:00
|
|
|
|
local options="--skip --force --pretend --quiet"
|
|
|
|
|
local actions="cd clone commit destroy diff generate help list open pull push rc show_path status symlink track unlink version"
|
|
|
|
|
local repos=$(\ls ~/.homesick/repos)
|
2017-10-10 18:07:01 +07:00
|
|
|
|
|
2023-10-01 03:32:03 +09:00
|
|
|
|
# Subcommand list
|
2023-10-01 03:40:52 +09:00
|
|
|
|
if ((COMP_CWORD == 1)); then
|
|
|
|
|
COMPREPLY=( $(compgen -W "${options} ${actions}" -- "$cur") )
|
2023-10-01 03:32:03 +09:00
|
|
|
|
return
|
2023-10-01 03:40:52 +09:00
|
|
|
|
fi
|
2017-10-10 18:07:01 +07:00
|
|
|
|
|
2023-10-01 03:32:03 +09:00
|
|
|
|
# Find the first non-switch word
|
|
|
|
|
local prev_index=1
|
2023-10-01 03:40:52 +09:00
|
|
|
|
local prev=${COMP_WORDS[prev_index]}
|
2023-10-01 03:32:03 +09:00
|
|
|
|
while [[ $prev == -* ]]; do
|
2023-10-01 03:40:52 +09:00
|
|
|
|
((++prev_index))
|
|
|
|
|
prev=${COMP_WORDS[prev_index]}
|
2023-10-01 03:32:03 +09:00
|
|
|
|
done
|
2017-10-10 18:07:01 +07:00
|
|
|
|
|
2023-10-01 03:32:03 +09:00
|
|
|
|
# Find the number of non-"--" commands
|
|
|
|
|
local num=0
|
2023-10-01 03:40:52 +09:00
|
|
|
|
for word in "${COMP_WORDS[@]}"; do
|
2023-10-01 03:32:03 +09:00
|
|
|
|
if [[ $word != -* ]]; then
|
2023-10-01 03:40:52 +09:00
|
|
|
|
((++num))
|
2023-10-01 03:32:03 +09:00
|
|
|
|
fi
|
|
|
|
|
done
|
2017-10-10 18:07:01 +07:00
|
|
|
|
|
2023-10-01 03:40:52 +09:00
|
|
|
|
case $prev in
|
2023-10-01 03:32:03 +09:00
|
|
|
|
# Commands that take a castle
|
|
|
|
|
cd|commit|destroy|diff|open|pull|push|rc|show_path|status|symlink|unlink)
|
2023-10-01 03:40:52 +09:00
|
|
|
|
COMPREPLY=( $(compgen -W "${repos}" -- "$cur") )
|
2023-10-01 03:32:03 +09:00
|
|
|
|
return
|
|
|
|
|
;;
|
|
|
|
|
# Commands that take command
|
|
|
|
|
help)
|
2023-10-01 03:40:52 +09:00
|
|
|
|
COMPREPLY=( $(compgen -W "${actions}" -- "$cur") )
|
2023-10-01 03:32:03 +09:00
|
|
|
|
return
|
|
|
|
|
;;
|
|
|
|
|
# Track command take file and repo
|
|
|
|
|
track)
|
2023-10-01 03:40:52 +09:00
|
|
|
|
if ((num == 2)); then
|
|
|
|
|
COMPREPLY=( $(compgen -X -f "$cur") )
|
|
|
|
|
elif ((num >= 3)); then
|
|
|
|
|
COMPREPLY=( $(compgen -W "${repos}" -- "$cur") )
|
2023-10-01 03:32:03 +09:00
|
|
|
|
fi
|
|
|
|
|
return
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2017-10-10 18:07:01 +07:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-01 03:19:46 +09:00
|
|
|
|
complete -o bashdefault -o default -F _omb_completion_homesick homesick
|