From f0a8f31d1b4ea9751734bc7e0149e062d9c74de2 Mon Sep 17 00:00:00 2001 From: Tin Lai Date: Thu, 28 May 2020 01:36:17 +1000 Subject: [PATCH 1/3] implement fish autocomplete --- completion/yadm.fish_completion | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 completion/yadm.fish_completion diff --git a/completion/yadm.fish_completion b/completion/yadm.fish_completion new file mode 100644 index 0000000..5c9792e --- /dev/null +++ b/completion/yadm.fish_completion @@ -0,0 +1,53 @@ +#!/usr/bin/fish + +function __fish_yadm_first_arg + set cmd (commandline -opc) + if [ (count $cmd) -eq 1 -a $cmd[1] = 'yadm' ] + return 0 + end + return 1 +end + +function __fish_yadm_using_command + set cmd (commandline -opc) + if [ (count $cmd) -gt 1 -a "x$argv[1]" = "x$cmd[-1]" ] + return 0 + end + return 1 +end + +# no dirs in complete list +complete -c yadm -x + +# yadm's specific autocomplete +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'clone' -d 'Clone an existing repository' +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'alt' -d 'Create links for alternates' +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'bootstrap' -d 'Execute $HOME/.config/yadm/bootstrap' +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'encrypt' -d 'Encrypt files' +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'perms' -d 'Fix perms for private files' +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'enter' -d 'Run sub-shell with GIT variables set' +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'git-crypt' -d 'Run git-crypt commands for the yadm repo' + +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'init' -d 'Initialize an empty repository' +complete -f -c yadm -n '__fish_yadm_using_command init' -s f + +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'list' -d 'List tracked files' +complete -f -c yadm -n '__fish_yadm_using_command list' -s a + +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'decrypt' -d 'Decrypt files' +complete -f -c yadm -n '__fish_yadm_using_command decrypt' -s l + +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'introspect' +complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "commands" +complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "configs" +complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "repo" +complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "switches" + +complete -f -c yadm -n '__fish_yadm_first_arg' -a 'config' -d 'Configure a setting' +for name in (yadm introspect configs) + complete -f -c yadm -n "__fish_yadm_using_command config" -a "$name" -d "yadm config" +end + +# wraps git's autocomplete +set -l GIT_DIR (yadm introspect repo) +complete -c yadm -w "git --git-dir $GIT_DIR" From f5e8599de40f94b1490ee664ba19a1c715f8ffd6 Mon Sep 17 00:00:00 2001 From: Tin Lai Date: Wed, 3 Jun 2020 18:02:04 +1000 Subject: [PATCH 2/3] improve fish completion by adding more completion options --- completion/yadm.fish_completion | 92 +++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/completion/yadm.fish_completion b/completion/yadm.fish_completion index 5c9792e..ffb9067 100644 --- a/completion/yadm.fish_completion +++ b/completion/yadm.fish_completion @@ -1,53 +1,77 @@ #!/usr/bin/fish -function __fish_yadm_first_arg - set cmd (commandline -opc) - if [ (count $cmd) -eq 1 -a $cmd[1] = 'yadm' ] +function __fish_yadm_universial_optspecs + string join \n 'a-yadm-dir=' 'b-yadm-repo=' 'c-yadm-config=' \ + 'd-yadm-encrypt=' 'e-yadm-archive=' 'f-yadm-bootstrap=' +end + +function __fish_yadm_needs_command + # Figure out if the current invocation already has a command. + set -l cmd (commandline -opc) + set -e cmd[1] + argparse -s (__fish_yadm_universial_optspecs) -- $cmd 2>/dev/null + or return 0 + if set -q argv[1] + echo $argv[1] + return 1 + end return 0 - end - return 1 end function __fish_yadm_using_command - set cmd (commandline -opc) - if [ (count $cmd) -gt 1 -a "x$argv[1]" = "x$cmd[-1]" ] - return 0 - end - return 1 + set -l cmd (__fish_yadm_needs_command) + test -z "$cmd" + and return 1 + contains -- $cmd $argv + and return 0 end -# no dirs in complete list -complete -c yadm -x - # yadm's specific autocomplete -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'clone' -d 'Clone an existing repository' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'alt' -d 'Create links for alternates' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'bootstrap' -d 'Execute $HOME/.config/yadm/bootstrap' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'encrypt' -d 'Encrypt files' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'perms' -d 'Fix perms for private files' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'enter' -d 'Run sub-shell with GIT variables set' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'git-crypt' -d 'Run git-crypt commands for the yadm repo' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'clone' -d 'Clone an existing repository' +complete -F -c yadm -n '__fish_yadm_using_command clone' -s w -d 'work-tree to use (default: $HOME)' +complete -f -c yadm -n '__fish_yadm_using_command clone' -s b -d 'branch to clone' +complete -x -c yadm -n '__fish_yadm_using_command clone' -s f -d 'force to overwrite' +complete -x -c yadm -n '__fish_yadm_using_command clone' -l bootstrap -d 'force bootstrap to run' +complete -x -c yadm -n '__fish_yadm_using_command clone' -l no-bootstrap -d 'prevent bootstrap from beingrun' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'init' -d 'Initialize an empty repository' -complete -f -c yadm -n '__fish_yadm_using_command init' -s f +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'alt' -d 'Create links for alternates' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'bootstrap' -d 'Execute $HOME/.config/yadm/bootstrap' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'perms' -d 'Fix perms for private files' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'enter' -d 'Run sub-shell with GIT variables set' +complete -c yadm -n '__fish_yadm_needs_command' -a 'git-crypt' -d 'Run git-crypt commands for the yadm repo' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'help' -d 'Print a summary of yadm commands' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'upgrade' -d 'Upgrade to version 2 of yadm directory structure' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'version' -d 'Print the version of yadm' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'list' -d 'List tracked files' -complete -f -c yadm -n '__fish_yadm_using_command list' -s a +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'init' -d 'Initialize an empty repository' +complete -x -c yadm -n '__fish_yadm_using_command init' -s f -d 'force to overwrite' +complete -F -c yadm -n '__fish_yadm_using_command init' -s w -d 'set work-tree (default: $HOME)' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'decrypt' -d 'Decrypt files' -complete -f -c yadm -n '__fish_yadm_using_command decrypt' -s l +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'list' -d 'List tracked files at current directory' +complete -x -c yadm -n '__fish_yadm_using_command list' -s a -d 'list all managed files instead' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'introspect' -complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "commands" -complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "configs" -complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "repo" -complete -f -c yadm -n '__fish_yadm_using_command introspect' -a "switches" +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'encrypt' -d 'Encrypt files' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'decrypt' -d 'Decrypt files' +complete -x -c yadm -n '__fish_yadm_using_command decrypt' -s l -d 'list the files stored without extracting' -complete -f -c yadm -n '__fish_yadm_first_arg' -a 'config' -d 'Configure a setting' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'introspect' -d 'Report internal yadm data' +complete -x -c yadm -n '__fish_yadm_using_command introspect' -a (printf -- '%s\n' 'commands configs repo switches') -d 'category' + +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'gitconfig' -d 'Pass options to the git config command' +complete -x -c yadm -n '__fish_yadm_needs_command' -a 'config' -d 'Configure a setting' for name in (yadm introspect configs) - complete -f -c yadm -n "__fish_yadm_using_command config" -a "$name" -d "yadm config" + complete -x -c yadm -n '__fish_yadm_using_command config' -a '$name' -d 'yadm config' end +# yadm universial options +complete --force-files -c yadm -s Y -l yadm-dir -d 'Override location of yadm directory' +complete --force-files -c yadm -l yadm-repo -d 'Override location of yadm repository' +complete --force-files -c yadm -l yadm-config -d 'Override location of yadm configuration file' +complete --force-files -c yadm -l yadm-encrypt -d 'Override location of yadm encryption configuration' +complete --force-files -c yadm -l yadm-archive -d 'Override location of yadm encrypted files archive' +complete --force-files -c yadm -l yadm-bootstrap -d 'Override location of yadm bootstrap program' + # wraps git's autocomplete set -l GIT_DIR (yadm introspect repo) -complete -c yadm -w "git --git-dir $GIT_DIR" +# setup the correct git-dir by appending it to git's argunment +complete -c yadm -w "git --git-dir=$GIT_DIR" From ecdc985ab04d0a876eb6be1417aeb706b3b2c5e5 Mon Sep 17 00:00:00 2001 From: Tin Lai Date: Thu, 4 Jun 2020 14:31:57 +1000 Subject: [PATCH 3/3] add manual entry for fish completions --- completion/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/completion/README.md b/completion/README.md index 69dae8b..71bda77 100644 --- a/completion/README.md +++ b/completion/README.md @@ -34,3 +34,7 @@ Load `_yadm` as a plugin in your `.zshrc`: fpath=("$ZPLUG_HOME/bin" $fpath) zplug "TheLocehiliosan/yadm", rename-to:_yadm, use:"completion/yadm.zsh_completion", as:command, defer:2 ``` + +## Fish completions +### Manual installation +Copy the completion script `yadm.fish_completion` locally, rename it to `yadm.fish`, and add it to any folder within `$fish_complete_path`. For example, for local installation, you can copy it to `$HOME/.config/fish/completions/` and it will be loaded when `yadm` is invoked.