mirror of https://github.com/kazhala/dotbare
Merge pull request #21 from kazhala/dev
commit
42fe532769
@ -0,0 +1,153 @@
|
||||
# shellcheck disable=SC2207
|
||||
|
||||
_dotbare_completion()
|
||||
{
|
||||
local IFS=$'\n' subcommands curr prev options verbose_options suggestions
|
||||
curr="${COMP_WORDS[$COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[$COMP_CWORD-1]}"
|
||||
|
||||
if [[ "$COMP_CWORD" -eq "1" ]]; then
|
||||
subcommands=$(
|
||||
dotbare -h \
|
||||
| awk '{
|
||||
if ($0 ~ /^ f.*/) {
|
||||
gsub(/^ /, "", $0)
|
||||
gsub(/\t\t/, " ", $0)
|
||||
print $0
|
||||
}
|
||||
}'
|
||||
)
|
||||
options=$(
|
||||
dotbare -h \
|
||||
| awk '{
|
||||
if ($0 ~ /^ -.*/) {
|
||||
gsub(/,/, " ", $0)
|
||||
gsub(/^ /, "", $0)
|
||||
gsub(/\t\t/, " ", $0)
|
||||
$2=""
|
||||
print $0
|
||||
}
|
||||
}'
|
||||
)
|
||||
verbose_options=$(dotbare -h | awk '$0 ~ /^ -.*/ {print $2}')
|
||||
if [[ "${curr}" == --* ]]; then
|
||||
suggestions=($(compgen -W "${verbose_options}" -- "${curr}"))
|
||||
elif [[ "${curr}" == -* ]]; then
|
||||
suggestions=($(compgen -W "${options}" -- "${curr}"))
|
||||
else
|
||||
suggestions=($(compgen -W "${subcommands}" -- "${curr}"))
|
||||
fi
|
||||
|
||||
elif [[ "${COMP_CWORD}" -eq 2 && "${prev}" == "-g" || "${prev}" == "--git" ]]; then
|
||||
subcommands=$(
|
||||
dotbare -h \
|
||||
| awk '{
|
||||
if ($0 ~ /^ f.*/) {
|
||||
if ($0 ~ /^ f(backup|init|upgrade).*/) {
|
||||
next
|
||||
}
|
||||
gsub(/^ /, "", $0)
|
||||
gsub(/\t\t/, " ", $0)
|
||||
print $0
|
||||
}
|
||||
}'
|
||||
)
|
||||
suggestions=($(compgen -W "${subcommands}" -- "${curr}"))
|
||||
|
||||
elif [[ "${COMP_WORDS[1]}" == "-g" || "${COMP_WORDS[1]}" == "--git" ]] && [[ "${COMP_CWORD}" -gt 2 ]]; then
|
||||
if [[ "${curr}" == --* && "${prev}" != "-h" && "${prev}" != "--help" ]]; then
|
||||
verbose_options=$(
|
||||
dotbare "${COMP_WORDS[2]}" -h 2> /dev/null \
|
||||
| awk '{
|
||||
if ($0 ~ /^ -p PATH/) {
|
||||
next
|
||||
} else if ($0 ~ /^ -u URL/) {
|
||||
next
|
||||
} else if ($0 ~ /^ -*/) {
|
||||
print $2
|
||||
}
|
||||
}'
|
||||
)
|
||||
suggestions=($(compgen -W "${verbose_options}" -- "${curr}"))
|
||||
elif [[ "${prev}" != "-h" && "${prev}" != "--help" ]]; then
|
||||
options=$(
|
||||
dotbare "${COMP_WORDS[2]}" -h 2> /dev/null \
|
||||
| awk '{
|
||||
gsub(/,/, " ", $0)
|
||||
if ($0 ~ /^ -p PATH/) {
|
||||
next
|
||||
} else if ($0 ~ /^ -u URL/) {
|
||||
next
|
||||
} else if ($0 ~ /^ -*/) {
|
||||
gsub(/^ /, "", $0)
|
||||
gsub(/\t/, " ", $0)
|
||||
$2=""
|
||||
print $0
|
||||
}
|
||||
}'
|
||||
)
|
||||
suggestions=($(compgen -W "${options}" -- "${curr}"))
|
||||
else
|
||||
return
|
||||
fi
|
||||
|
||||
elif [[ "${COMP_WORDS[1]}" == "fbackup" ]] && [[ "${prev}" == "-p" || "${prev}" == "--path" ]]; then
|
||||
COMPREPLY=($(compgen -d -- "${curr}"))
|
||||
return
|
||||
elif [[ "${COMP_WORDS[1]}" == "finit" ]] && [[ "${prev}" == "-u" || "${prev}" == "--url" ]]; then
|
||||
return
|
||||
elif [[ "${curr}" == --* && "${prev}" != "-h" && "${prev}" != "--help" ]]; then
|
||||
verbose_options=$(
|
||||
dotbare "${COMP_WORDS[1]}" -h 2> /dev/null \
|
||||
| awk '{
|
||||
if ($0 ~ /^ -p PATH/) {
|
||||
print "--path"
|
||||
} else if ($0 ~ /^ -u URL/) {
|
||||
print "--url"
|
||||
} else if ($0 ~ /^ -c COL/) {
|
||||
print "--col"
|
||||
} else if ($0 ~ /^ -*/) {
|
||||
print $2
|
||||
}
|
||||
}'
|
||||
)
|
||||
suggestions=($(compgen -W "${verbose_options}" -- "${curr}"))
|
||||
elif [[ "${prev}" != "-h" && "${prev}" != "--help" ]]; then
|
||||
options=$(
|
||||
dotbare "${COMP_WORDS[1]}" -h 2> /dev/null \
|
||||
| awk '{
|
||||
gsub(/,/, " ", $0)
|
||||
if ($0 ~ /^ -p PATH/) {
|
||||
gsub(/^ -p PATH --path PATH/, "-p", $0)
|
||||
gsub(/\t/, " ", $0)
|
||||
print $0
|
||||
} else if ($0 ~ /^ -u URL/) {
|
||||
gsub(/^ -u URL --url URL/, "-u", $0)
|
||||
gsub(/\t/, " ", $0)
|
||||
print $0
|
||||
} else if ($0 ~ /^ -c COL/) {
|
||||
gsub(/^ -c COL --col COL/, "-c", $0)
|
||||
gsub(/\t/, " ", $0)
|
||||
print $0
|
||||
} else if ($0 ~ /^ -*/) {
|
||||
gsub(/^ /, "", $0)
|
||||
gsub(/\t/, " ", $0)
|
||||
$2=""
|
||||
print $0
|
||||
}
|
||||
}'
|
||||
)
|
||||
suggestions=($(compgen -W "${options}" -- "${curr}"))
|
||||
fi
|
||||
|
||||
if [[ "${#suggestions[*]}" -eq 1 ]]; then
|
||||
COMPREPLY=("${suggestions[@]%% *}")
|
||||
else
|
||||
for i in "${!suggestions[@]}"; do
|
||||
suggestions[$i]="$(printf '%*s' "-$COLUMNS" "${suggestions[$i]}")"
|
||||
done
|
||||
COMPREPLY=("${suggestions[@]}")
|
||||
fi
|
||||
}
|
||||
|
||||
complete -F _dotbare_completion dotbare
|
@ -0,0 +1,137 @@
|
||||
#compdef dotbare
|
||||
|
||||
_dotbare() {
|
||||
local context state state_descr line ret curcontext
|
||||
local -A opt_args
|
||||
ret=1
|
||||
curcontext="${curcontext}"
|
||||
|
||||
_arguments -C \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(- : *)'{-v,--version}'[display dotbare version]' \
|
||||
'(-g --git)'{-g,--git}'[use dotbare as a generic fuzzy git tool and operate in current git directory]' \
|
||||
'1:cmds:->cmds' \
|
||||
'*::options:->options' \
|
||||
&& ret=0
|
||||
|
||||
case "${state}" in
|
||||
cmds)
|
||||
local subcommands
|
||||
subcommands=(
|
||||
'fadd:stage files'
|
||||
'fbackup:backup files'
|
||||
'fcheckout:checkout file/branch/commit'
|
||||
'fedit:edit files'
|
||||
'fgrep:grep within tracked files'
|
||||
'finit:init/migrate dotbare'
|
||||
'flog:interactive log viewer'
|
||||
'freset:reset files/commit'
|
||||
'fstash:stage management'
|
||||
'fstat:toggle stage/unstage of files'
|
||||
'funtrack:untrack files'
|
||||
'fupgrade:update dotbare'
|
||||
)
|
||||
_describe 'command' subcommands \
|
||||
&& ret=0
|
||||
;;
|
||||
options)
|
||||
case "${line[1]}" in
|
||||
fadd)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-f --file -d --dir -h --help)'{-f,--file}'[select files from PWD and stage]' \
|
||||
'(-d --dir -f --file -h --help)'{-d,--dir}'[select directory from PWD and stage]' \
|
||||
&& ret=0
|
||||
;;
|
||||
fbackup)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-s --select -p --path -h --help)'{-s,--select}'[select tracked files to backup]' \
|
||||
'(-p --path -s --select -h --help)'{-p,--path}'[sepcify path of files to backup]:filename:_files' \
|
||||
'(-m --move -h --help)'{-m,--move}'[use mv cmd instead of cp cmd]' \
|
||||
&& ret=0
|
||||
;;
|
||||
fcheckout)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-s --select -b --branch -c --commit -h --help)'{-s,--select}'[select files and then checkout them in selected commits]' \
|
||||
'(-b --branch -s --select -c --commit -h --help)'{-b,--branch}'[checkout branch]' \
|
||||
'(-c --commit -b --branch -s --select -h --help)'{-c,--commit}'[checkout commit]' \
|
||||
'(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \
|
||||
&& ret=0
|
||||
;;
|
||||
fedit)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-m --modified -c --commit -h --help)'{-m,--modified}'[edit modified files]' \
|
||||
'(-c --commit -m --modified -h --help)'{-c,--commit}'[edit commits]' \
|
||||
&& ret=0
|
||||
;;
|
||||
fgrep)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-f --full -c --col)'{-f,--full}'[include all columns during fzf search, as if using "--col 1"]' \
|
||||
'(-f --full -c --col)'{-c,--col}'[specify a column number to start searching in fzf]: :->cols' \
|
||||
&& ret=0
|
||||
;;
|
||||
finit)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-u --url -h --help)'{-u,--url}'[migrate remote dotfiles to current system]: :->url' \
|
||||
'(-s --submodule -h --help)'{-s,--submodule}'[clone submodules during migration]' \
|
||||
'(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \
|
||||
&& ret=0
|
||||
;;
|
||||
flog)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-r --revert -R --reset -e --edit -c --checkout -h --help)'{-r,--revert}'[revert the selected commit and skip action menu]' \
|
||||
'(-r --revert -R --reset -e --edit -c --checkout -h --help)'{-R,--reset}'[reset the selected commit and skip action menu]' \
|
||||
'(-r --revert -R --reset -e --edit -c --checkout -h --help)'{-e,--edit}'[edit the selected commit and skip action menu]' \
|
||||
'(-r --revert -R --reset -e --edit -c --checkout -h --help)'{-c,--checkout}'[checkout the selected commit and skip action menu]' \
|
||||
'(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \
|
||||
&& ret=0
|
||||
;;
|
||||
freset)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-c --commit -h --help)'{-c,--commit}'[reset HEAD to certain commit]' \
|
||||
'(-S --soft -H --hard -h --help)'{-S,--soft}'[reset commit using --soft flag]' \
|
||||
'(-H --hard -S --soft -h --help)'{-H,--hard}'[reset commit using --hard flag]' \
|
||||
'(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \
|
||||
&& ret=0
|
||||
;;
|
||||
fstash)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-s --select -d --delete -p --pop -h --help)'{-s,--select}'[list modified files and stash the selected files]' \
|
||||
'(-s --select -d --delete -p --pop -h --help)'{-d,--delete}'[list stash and delete the selected stash]' \
|
||||
'(-s --select -d --delete -p --pop -h --help)'{-p,--pop}'[use "stash pop" instead of "stash apply"]' \
|
||||
&& ret=0
|
||||
;;
|
||||
fstat)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
funtrack)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
'(-t --temp -r --resume -h --help)'{-t,--temp}'[temporarily ignore changes of the selected files]' \
|
||||
'(-t --temp -r --resume -h --help)'{-r,--resume}'[resume tracking changes of the selected files]' \
|
||||
'(-y --yes -h --help)'{-y,--yes}'[acknowledge all actions and skip confirmation]' \
|
||||
&& ret=0
|
||||
;;
|
||||
fupgrade)
|
||||
_arguments \
|
||||
'(- : *)'{-h,--help}'[show help information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
return "${ret}";
|
||||
}
|
||||
|
||||
_dotbare "$@"
|
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_DIR=/opt/dotbare
|
||||
${SCRIPT_DIR}/dotbare "$@"
|
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SCRIPT_DIR=/usr/local/Cellar/dotbare/1.3.0
|
||||
${SCRIPT_DIR}/dotbare "$@"
|
Loading…
Reference in New Issue