diff --git a/dotbare.plugin.bash b/dotbare.plugin.bash index b9fda84..34b25ae 100644 --- a/dotbare.plugin.bash +++ b/dotbare.plugin.bash @@ -41,6 +41,59 @@ __dotbare_completion() suggestions=($(compgen -W "${subcommands}" -- "${curr}")) fi + elif [[ "${COMP_CWORD}" -eq 2 && "${prev}" == "-g" || "${prev}" == "--git" ]]; then + subcommands=$( + "${mydir}"/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=$( + "${mydir}"/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=$( + "${mydir}"/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" ]]; then COMPREPLY=($(compgen -d -- "${curr}")) return diff --git a/dotbare.plugin.zsh b/dotbare.plugin.zsh index d343725..4f416a4 100644 --- a/dotbare.plugin.zsh +++ b/dotbare.plugin.zsh @@ -14,6 +14,7 @@ __dotbare_completion() { _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