1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-15 07:00:04 +00:00

adding completion scripts for #97

This commit is contained in:
deadc0de6
2019-03-06 22:00:16 +01:00
parent 0ccb35e9b0
commit 5bb068e35b
6 changed files with 745 additions and 0 deletions

View File

@@ -137,6 +137,8 @@ shell with the config file path, for example
alias dotdrop=<absolute-path-to-dotdrop.sh> --cfg=<path-to-your-config.yaml>'
```
For bash and zsh completion scripts, see [the related doc](completion/README.md).
Finally import your dotfiles as described [below](#usage).
# Usage

21
completion/README.md Normal file
View File

@@ -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)

View File

@@ -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=('<key>')
_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=('<path>')
_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=('<path>')
_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=('<key>')
_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 "$@"

View File

@@ -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=('<key>')
_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=('<path>')
_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=('<path>')
_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=('<key>')
_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 "$@"

View File

@@ -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

View File

@@ -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