diff --git a/README.md b/README.md index f188b51..48b3bb9 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,8 @@ shell with the config file path, for example alias dotdrop= --cfg=' ``` +For bash and zsh completion scripts, see [the related doc](completion/README.md). + Finally import your dotfiles as described [below](#usage). # Usage diff --git a/completion/README.md b/completion/README.md new file mode 100644 index 0000000..6f7ac25 --- /dev/null +++ b/completion/README.md @@ -0,0 +1,21 @@ +Here are the completion files for `bash` and `zsh` +for the use of dotdrop either through the bash script `dotdrop.sh` +or through the python script `dotdrop` (pypi, snap, setup.py, etc). + +Those files are generated using +[infi.docopt_completion](https://github.com/Infinidat/infi.docopt_completion). + +# bash + +Source the file + +* if using `dotdrop.sh` [dotdrop.sh-completion.bash](completion/dotdrop.sh-completion.bash) +* if using `dotdrop`: [dotdrop-completion.bash](completion/dotdrop-completion.bash) + +# zsh + +Copy the file `_dotdrop.sh-completion.zsh` +in a path within `${fpath}` + +* if using `dotdrop.sh`: [_dotdrop.sh-completion.zsh](_dotdrop.sh-completion.zsh) +* if using `dotdrop`: [_dotdrop-completion.zsh](_dotdrop-completion.zsh) diff --git a/completion/_dotdrop-completion.zsh b/completion/_dotdrop-completion.zsh new file mode 100644 index 0000000..3965dd5 --- /dev/null +++ b/completion/_dotdrop-completion.zsh @@ -0,0 +1,254 @@ +#compdef dotdrop + +_message_next_arg() +{ + argcount=0 + for word in "${words[@][2,-1]}" + do + if [[ $word != -* ]] ; then + ((argcount++)) + fi + done + if [[ $argcount -le ${#myargs[@]} ]] ; then + _message -r $myargs[$argcount] + if [[ $myargs[$argcount] =~ ".*file.*" || $myargs[$argcount] =~ ".*path.*" ]] ; then + _files + fi + fi +} + +_dotdrop () +{ + local context state state_descr line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '(-h)-h[Show this screen.]' \ + '(--help)--help[Show this screen.]' \ + '(-v)-v[Show version.]' \ + '(--version)--version[Show version.]' \ + '*::options:->options' + + case $state in + (command) + local -a subcommands + subcommands=( + 'install' + 'import' + 'compare' + 'update' + 'listfiles' + 'detail' + 'list' + ) + _values 'dotdrop' $subcommands + ;; + + (options) + case $line[1] in + install) + _dotdrop-install + ;; + import) + _dotdrop-import + ;; + compare) + _dotdrop-compare + ;; + update) + _dotdrop-update + ;; + listfiles) + _dotdrop-listfiles + ;; + detail) + _dotdrop-detail + ;; + list) + _dotdrop-list + ;; + esac + ;; + esac + +} + +_dotdrop-install () +{ + local context state state_descr line + typeset -A opt_args + + if [[ $words[$CURRENT] == -* ]] ; then + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-t)-t' \ + '(--temp)--temp' \ + '(-f)-f' \ + '(--force)--force' \ + '(-n)-n' \ + '(--nodiff)--nodiff' \ + '(-d)-d' \ + '(--dry)--dry' \ + '(-D)-D' \ + '(--showdiff)--showdiff' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + + else + myargs=('') + _message_next_arg + fi +} + +_dotdrop-import () +{ + local context state state_descr line + typeset -A opt_args + + if [[ $words[$CURRENT] == -* ]] ; then + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-l)-l' \ + '(--inv-link)--inv-link' \ + '(-d)-d' \ + '(--dry)--dry' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + + else + myargs=('') + _message_next_arg + fi +} + +_dotdrop-compare () +{ + local context state state_descr line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + '(-o=-)-o=-' \ + '(--dopts=-)--dopts=-' \ + '(-C=-)-C=-' \ + '(--file=-)--file=-' \ + '(-i=-)-i=-' \ + '(--ignore=-)--ignore=-' \ + +} + +_dotdrop-update () +{ + local context state state_descr line + typeset -A opt_args + + if [[ $words[$CURRENT] == -* ]] ; then + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-f)-f' \ + '(--force)--force' \ + '(-d)-d' \ + '(--dry)--dry' \ + '(-k)-k' \ + '(--key)--key' \ + '(-P)-P' \ + '(--show-patch)--show-patch' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + '(-i=-)-i=-' \ + '(--ignore=-)--ignore=-' \ + + else + myargs=('') + _message_next_arg + fi +} + +_dotdrop-listfiles () +{ + local context state state_descr line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-T)-T' \ + '(--template)--template' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + +} + +_dotdrop-detail () +{ + local context state state_descr line + typeset -A opt_args + + if [[ $words[$CURRENT] == -* ]] ; then + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + + else + myargs=('') + _message_next_arg + fi +} + +_dotdrop-list () +{ + local context state state_descr line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + +} + + +_dotdrop "$@" \ No newline at end of file diff --git a/completion/_dotdrop.sh-completion.zsh b/completion/_dotdrop.sh-completion.zsh new file mode 100644 index 0000000..7881285 --- /dev/null +++ b/completion/_dotdrop.sh-completion.zsh @@ -0,0 +1,254 @@ +#compdef dotdrop.sh + +_message_next_arg() +{ + argcount=0 + for word in "${words[@][2,-1]}" + do + if [[ $word != -* ]] ; then + ((argcount++)) + fi + done + if [[ $argcount -le ${#myargs[@]} ]] ; then + _message -r $myargs[$argcount] + if [[ $myargs[$argcount] =~ ".*file.*" || $myargs[$argcount] =~ ".*path.*" ]] ; then + _files + fi + fi +} + +_dotdrop.sh () +{ + local context state state_descr line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '(-h)-h[Show this screen.]' \ + '(--help)--help[Show this screen.]' \ + '(-v)-v[Show version.]' \ + '(--version)--version[Show version.]' \ + '*::options:->options' + + case $state in + (command) + local -a subcommands + subcommands=( + 'install' + 'import' + 'compare' + 'update' + 'listfiles' + 'detail' + 'list' + ) + _values 'dotdrop.sh' $subcommands + ;; + + (options) + case $line[1] in + install) + _dotdrop.sh-install + ;; + import) + _dotdrop.sh-import + ;; + compare) + _dotdrop.sh-compare + ;; + update) + _dotdrop.sh-update + ;; + listfiles) + _dotdrop.sh-listfiles + ;; + detail) + _dotdrop.sh-detail + ;; + list) + _dotdrop.sh-list + ;; + esac + ;; + esac + +} + +_dotdrop.sh-install () +{ + local context state state_descr line + typeset -A opt_args + + if [[ $words[$CURRENT] == -* ]] ; then + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-t)-t' \ + '(--temp)--temp' \ + '(-f)-f' \ + '(--force)--force' \ + '(-n)-n' \ + '(--nodiff)--nodiff' \ + '(-d)-d' \ + '(--dry)--dry' \ + '(-D)-D' \ + '(--showdiff)--showdiff' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + + else + myargs=('') + _message_next_arg + fi +} + +_dotdrop.sh-import () +{ + local context state state_descr line + typeset -A opt_args + + if [[ $words[$CURRENT] == -* ]] ; then + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-l)-l' \ + '(--inv-link)--inv-link' \ + '(-d)-d' \ + '(--dry)--dry' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + + else + myargs=('') + _message_next_arg + fi +} + +_dotdrop.sh-compare () +{ + local context state state_descr line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + '(-o=-)-o=-' \ + '(--dopts=-)--dopts=-' \ + '(-C=-)-C=-' \ + '(--file=-)--file=-' \ + '(-i=-)-i=-' \ + '(--ignore=-)--ignore=-' \ + +} + +_dotdrop.sh-update () +{ + local context state state_descr line + typeset -A opt_args + + if [[ $words[$CURRENT] == -* ]] ; then + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-f)-f' \ + '(--force)--force' \ + '(-d)-d' \ + '(--dry)--dry' \ + '(-k)-k' \ + '(--key)--key' \ + '(-P)-P' \ + '(--show-patch)--show-patch' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + '(-i=-)-i=-' \ + '(--ignore=-)--ignore=-' \ + + else + myargs=('') + _message_next_arg + fi +} + +_dotdrop.sh-listfiles () +{ + local context state state_descr line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-T)-T' \ + '(--template)--template' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + +} + +_dotdrop.sh-detail () +{ + local context state state_descr line + typeset -A opt_args + + if [[ $words[$CURRENT] == -* ]] ; then + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + '(-p=-)-p=-' \ + '(--profile=-)--profile=-' \ + + else + myargs=('') + _message_next_arg + fi +} + +_dotdrop.sh-list () +{ + local context state state_descr line + typeset -A opt_args + + _arguments -C \ + ':command:->command' \ + '(-V)-V' \ + '(--verbose)--verbose' \ + '(-b)-b' \ + '(--no-banner)--no-banner' \ + '(-c=-)-c=-' \ + '(--cfg=-)--cfg=-' \ + +} + + +_dotdrop.sh "$@" \ No newline at end of file diff --git a/completion/dotdrop-completion.bash b/completion/dotdrop-completion.bash new file mode 100644 index 0000000..2aab93e --- /dev/null +++ b/completion/dotdrop-completion.bash @@ -0,0 +1,107 @@ + +_dotdrop() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W '-h --help -v --version install import compare update listfiles detail list' -- $cur) ) + else + case ${COMP_WORDS[1]} in + install) + _dotdrop_install + ;; + import) + _dotdrop_import + ;; + compare) + _dotdrop_compare + ;; + update) + _dotdrop_update + ;; + listfiles) + _dotdrop_listfiles + ;; + detail) + _dotdrop_detail + ;; + list) + _dotdrop_list + ;; + esac + + fi +} + +_dotdrop_install() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -t --temp -f --force -n --nodiff -d --dry -D --showdiff -c= --cfg= -p= --profile= ' -- $cur) ) + fi +} + +_dotdrop_import() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -l --inv-link -d --dry -c= --cfg= -p= --profile= ' -- $cur) ) + fi +} + +_dotdrop_compare() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -W '-V --verbose -b --no-banner -c= --cfg= -p= --profile= -o= --dopts= -C= --file= -i= --ignore= ' -- $cur) ) + fi +} + +_dotdrop_update() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -f --force -d --dry -k --key -P --show-patch -c= --cfg= -p= --profile= -i= --ignore= ' -- $cur) ) + fi +} + +_dotdrop_listfiles() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -W '-V --verbose -b --no-banner -T --template -c= --cfg= -p= --profile= ' -- $cur) ) + fi +} + +_dotdrop_detail() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -c= --cfg= -p= --profile= ' -- $cur) ) + fi +} + +_dotdrop_list() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -W '-V --verbose -b --no-banner -c= --cfg= ' -- $cur) ) + fi +} + +complete -o bashdefault -o default -o filenames -F _dotdrop dotdrop \ No newline at end of file diff --git a/completion/dotdrop.sh-completion.bash b/completion/dotdrop.sh-completion.bash new file mode 100644 index 0000000..b849d09 --- /dev/null +++ b/completion/dotdrop.sh-completion.bash @@ -0,0 +1,107 @@ + +_dotdropsh() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=( $( compgen -W '-h --help -v --version install import compare update listfiles detail list' -- $cur) ) + else + case ${COMP_WORDS[1]} in + install) + _dotdropsh_install + ;; + import) + _dotdropsh_import + ;; + compare) + _dotdropsh_compare + ;; + update) + _dotdropsh_update + ;; + listfiles) + _dotdropsh_listfiles + ;; + detail) + _dotdropsh_detail + ;; + list) + _dotdropsh_list + ;; + esac + + fi +} + +_dotdropsh_install() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -t --temp -f --force -n --nodiff -d --dry -D --showdiff -c= --cfg= -p= --profile= ' -- $cur) ) + fi +} + +_dotdropsh_import() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -l --inv-link -d --dry -c= --cfg= -p= --profile= ' -- $cur) ) + fi +} + +_dotdropsh_compare() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -W '-V --verbose -b --no-banner -c= --cfg= -p= --profile= -o= --dopts= -C= --file= -i= --ignore= ' -- $cur) ) + fi +} + +_dotdropsh_update() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -f --force -d --dry -k --key -P --show-patch -c= --cfg= -p= --profile= -i= --ignore= ' -- $cur) ) + fi +} + +_dotdropsh_listfiles() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -W '-V --verbose -b --no-banner -T --template -c= --cfg= -p= --profile= ' -- $cur) ) + fi +} + +_dotdropsh_detail() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -fW '-V --verbose -b --no-banner -c= --cfg= -p= --profile= ' -- $cur) ) + fi +} + +_dotdropsh_list() +{ + local cur + cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -ge 2 ]; then + COMPREPLY=( $( compgen -W '-V --verbose -b --no-banner -c= --cfg= ' -- $cur) ) + fi +} + +complete -o bashdefault -o default -o filenames -F _dotdropsh dotdrop.sh \ No newline at end of file