dotfiles script v0.3.0: added bash-completion
This commit is contained in:
parent
801cabcba4
commit
885c75654f
|
|
@ -0,0 +1,7 @@
|
|||
# ~/.bash_completion - Custom bash auto completions
|
||||
|
||||
# Enable bash completion for dotfiles manager (if installed)
|
||||
if command -v dotfiles &>/dev/null; then
|
||||
source <(dotfiles bash-completion)
|
||||
fi
|
||||
|
||||
42
bin/dotfiles
42
bin/dotfiles
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
##
|
||||
## binaryDiv's dotfiles management script
|
||||
## Version 0.2.0
|
||||
## Version 0.3.0
|
||||
##
|
||||
|
||||
usage() {
|
||||
|
|
@ -125,6 +125,46 @@ case "$cmd" in
|
|||
git -C "$dotfilesdir" pull "$@"
|
||||
;;
|
||||
|
||||
bash-completion)
|
||||
cat <<- 'END_OF_BASHCOMPLETION'
|
||||
_dotfiles_filenames() {
|
||||
compopt -o filenames
|
||||
files=($(compgen -f -X '*/@(.|..|.git)' .dotfiles/$cur))
|
||||
COMPREPLY=(${files[@]#.dotfiles/})
|
||||
}
|
||||
_dotfiles() {
|
||||
COMPREPLY=()
|
||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
local commands="help install ls diff link git pull"
|
||||
local gitcommands="add commit diff fetch log pull push rebase status"
|
||||
|
||||
if [[ $COMP_CWORD -eq 1 ]]; then
|
||||
COMPREPLY=($(compgen -W "$commands" -- $cur))
|
||||
else
|
||||
case "${COMP_WORDS[1]}" in
|
||||
ls|diff)
|
||||
[[ $COMP_CWORD -eq 2 ]] && _dotfiles_filenames
|
||||
;;
|
||||
|
||||
link)
|
||||
_dotfiles_filenames
|
||||
;;
|
||||
|
||||
git)
|
||||
if [[ $COMP_CWORD -eq 2 ]]; then
|
||||
COMPREPLY=($(compgen -W "$gitcommands" -- ${cur}))
|
||||
else
|
||||
_dotfiles_filenames
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _dotfiles dotfiles
|
||||
END_OF_BASHCOMPLETION
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown command '$cmd', use 'help' to show all commands."
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Reference in New Issue