dotfiles/dotlib/tab.sh

38 lines
820 B
Bash

_ssh_hosts() {
mapfile -t hosts < <(awk 'tolower($1) == "host" { print $2 }' ~/.ssh/config)
mapfile -t COMPREPLY < <(compgen -W "${hosts[*]}" -- "${COMP_WORDS[COMP_CWORD]}")
return 0
}
complete -o default -F _ssh_hosts ssh scp ssh-copy-id sftp
_make_targets() {
local arg prev file targets
if [[ -f makefile ]]; then
file=makefile
elif [[ -f Makefile ]]; then
file=Makefile
fi
for arg in "${COMP_WORDS[@]}"; do
if [[ $prev = -f ]]; then
file=$arg
elif [[ $arg = -f* ]]; then
file=${arg#-f}
fi
prev=$arg
done
mapfile -t targets < <(
awk '$1 ~ /:$/ && $1 !~ /^\./ { gsub(/:$/, "", $1); print $1 }' "$file"
)
mapfile -t COMPREPLY < <(
compgen -W "${targets[*]}" -- "${COMP_WORDS[COMP_CWORD]}"
)
}
complete -o default -F _make_targets make gmake