From 1ce27e6d4b832cb05591492c852020499ed9b686 Mon Sep 17 00:00:00 2001 From: lelgenio Date: Tue, 23 Jun 2020 00:50:34 -0300 Subject: [PATCH 1/2] fish completion: add key and profile completion --- completion/dotdrop.fish | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/completion/dotdrop.fish b/completion/dotdrop.fish index ffab682..95db195 100644 --- a/completion/dotdrop.fish +++ b/completion/dotdrop.fish @@ -19,6 +19,31 @@ function comp_opt -a "command" $argv[2..-1] end +function list_profiles + dotdrop profiles \ + --grepable \ + --no-banner \ + 2> /dev/null +end + +function list_test_keys -a "test_arg" + # Return only dotdrop keys in which the src field matches a test(1) criteria + # ^⌣ ^ ← "Slide Time!!" + dotdrop files \ + --grepable \ + --no-banner \ + 2> /dev/null | + while read line + # Single use variable because fish's output capture may change soon + set -l dst (echo $line | cut -d, -f2 | cut -d: -f2 ) + if test $test_arg "$dst" + echo $line + end + end | + cut -d, -f1 +end + + # Complete subcommands # comp_sub -a "install" -d "Install dotfiles" @@ -98,7 +123,8 @@ comp_opt "files profiles"\ # comp_opt "install import compare update remove files detail"\ -x -s p -l profile\ - -d "Specify the profile to use [default: "(uname -n)"]" + -d "Specify the profile to use [default: "(uname -n)"]"\ + -a "(list_profiles)" comp_opt "compare update"\ -x -s i -l ignore\ @@ -129,12 +155,15 @@ comp_opt "update"\ comp_opt "remove"\ -F -# TODO: complete keys -comp_opt "install"\ - -f +comp_opt "install detail"\ + -f\ + -d "File"\ + -a "(list_test_keys -f)" -comp_opt "detail"\ - -f +comp_opt "install detail"\ + -f\ + -d "Directory"\ + -a "(list_test_keys -d)" # dotdrop.sh # From 2daefc2aa314be9eb1cf6fd6e8d9068545b6d539 Mon Sep 17 00:00:00 2001 From: lelgenio Date: Tue, 23 Jun 2020 01:25:44 -0300 Subject: [PATCH 2/2] fish completion: sort subcommands by importance/like -h --- completion/dotdrop.fish | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/completion/dotdrop.fish b/completion/dotdrop.fish index 95db195..d8e3b73 100644 --- a/completion/dotdrop.fish +++ b/completion/dotdrop.fish @@ -46,14 +46,14 @@ end # Complete subcommands # -comp_sub -a "install" -d "Install dotfiles" -comp_sub -a "import" -d "Import dotfiles into dotdrop" -comp_sub -a "compare" -d "Compare your local dotfiles with managed dotfiles" -comp_sub -a "update" -d "Update a managed dotfile" -comp_sub -a "remove" -d "Remove a managed dotfile" -comp_sub -a "files" -d "List managed dotfiles" -comp_sub -a "detail" -d "List managed dotfiles details" -comp_sub -a "profiles" -d "List available profiles" +comp_sub -k -a "profiles" -d "List available profiles" +comp_sub -k -a "detail" -d "List managed dotfiles details" +comp_sub -k -a "files" -d "List managed dotfiles" +comp_sub -k -a "remove" -d "Remove a managed dotfile" +comp_sub -k -a "update" -d "Update a managed dotfile" +comp_sub -k -a "compare" -d "Compare your local dotfiles with managed dotfiles" +comp_sub -k -a "import" -d "Import dotfiles into dotdrop" +comp_sub -k -a "install" -d "Install dotfiles" # Lone options #