From c6fae4977e9197d78039760c71b63eb4387cb4dc Mon Sep 17 00:00:00 2001 From: Niam Patel Date: Sun, 10 Jan 2021 19:55:58 +0000 Subject: [PATCH 1/6] Inital fish-completion version --- completions/__stup_complete.fish | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 completions/__stup_complete.fish diff --git a/completions/__stup_complete.fish b/completions/__stup_complete.fish new file mode 100644 index 0000000..2b7df79 --- /dev/null +++ b/completions/__stup_complete.fish @@ -0,0 +1,43 @@ +set -l times week month year previous-week previous-month previous-year +set -l commands show add edit copy log search add-category list-category set-category order-category rename-category usage version +set -l paged_commands log usage +set -l note_commands add +set -l dated_commands show add edit +set -l ranged_commands copy log search +set -l name_cat_commands add-category rename-category +set -l desc_cat_commands add-category set-category +set -l cat_commands show add edit copy log search set-category rename-category + +# disable file completions +complete -c stup -f + +# subcommands listed in $commands +complete -c stup -n "not __fish_seen_subcommand_from $commands" -x -a "$commands" + +# version and help +complete -c stup -s v -l version -d "Print current version" +complete -c stup -s h -l help + +# @/at options +complete -c stup -n "__fish_seen_subcommand_from $dated_commands" -s "@" -l at -d "Note timestamp" + +# from/to options +complete -c stup -n "__fish_seen_subcommand_from $ranged_commands" -s f -l from +complete -c stup -n "__fish_seen_subcommand_from $ranged_commands" -s t -l to + +complete -c stup -n "__fish_contains_opt -s @ at ; and __fish_seen_subcommand_from $dated_commands" -x -a "$times" +complete -c stup -n "__fish_contains_opt -s f from ; or __fish_contains_opt -s t to ; and __fish_seen_subcommand_from $ranged_commands" -x -a "$times" + +# note options +complete -c stup -n "__fish_seen_subcommand_from $note_commands" -s n -l note + +# add (no-)pager option for paged commands +complete -c stup -n "__fish_seen_subcommand_from $paged_commands" -l no-pager -d "Disable pager" +complete -c stup -n "__fish_seen_subcommand_from $paged_commands" -l pager -d "Use pager" + +# store category directory and complete from the contained category file +cat "$HOME/.config/stup.conf" | read -d = -l _ category_dir +complete -c stup -n "__fish_seen_subcommand_from $cat_commands" -s c -l category -a "(cat $category_dir/categories.conf)" + +complete -c stup -n "__fish_seen_subcommand_from $name_cat_commands" -l category-name +complete -c stup -n "__fish_seen_subcommand_from $desc_cat_commands" -l category-description From d03e244c4af31f51d29a797281f194861f4c7b28 Mon Sep 17 00:00:00 2001 From: Niam Patel Date: Sun, 17 Jan 2021 22:26:37 +0000 Subject: [PATCH 2/6] Add default stup complete, shift line order --- completions/__stup_complete.fish | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/completions/__stup_complete.fish b/completions/__stup_complete.fish index 2b7df79..5e82ebf 100644 --- a/completions/__stup_complete.fish +++ b/completions/__stup_complete.fish @@ -1,12 +1,17 @@ +#!/usr/bin/env fish + set -l times week month year previous-week previous-month previous-year -set -l commands show add edit copy log search add-category list-category set-category order-category rename-category usage version +set -l commands show add edit copy log search add-category list-category set-category order-category rename-category usage set -l paged_commands log usage set -l note_commands add set -l dated_commands show add edit set -l ranged_commands copy log search +set -l cat_commands show add edit copy log search set-category rename-category set -l name_cat_commands add-category rename-category set -l desc_cat_commands add-category set-category -set -l cat_commands show add edit copy log search set-category rename-category + +# read category file path from config +cat "$HOME/.config/stup.conf" | read -d = -l _ category_dir # disable file completions complete -c stup -f @@ -14,6 +19,11 @@ complete -c stup -f # subcommands listed in $commands complete -c stup -n "not __fish_seen_subcommand_from $commands" -x -a "$commands" +# default `add` behaviour with no subcommands +complete -c stup -n "not __fish_seen_subcommand_from $commands" -s "@" -l at -d "Note timestamp" +complete -c stup -n "not __fish_seen_subcommand_from $commands" -s c -l category -a "(cat $category_dir/categories.conf)" +complete -c stup -n "not __fish_seen_subcommand_from $commands" -s n -l note + # version and help complete -c stup -s v -l version -d "Print current version" complete -c stup -s h -l help @@ -29,14 +39,13 @@ complete -c stup -n "__fish_contains_opt -s @ at ; and __fish_seen_subcommand_fr complete -c stup -n "__fish_contains_opt -s f from ; or __fish_contains_opt -s t to ; and __fish_seen_subcommand_from $ranged_commands" -x -a "$times" # note options -complete -c stup -n "__fish_seen_subcommand_from $note_commands" -s n -l note +complete -c stup -n "__fish_seen_subcommand_from $note_commands" -s n -l note -d "Note content" # add (no-)pager option for paged commands complete -c stup -n "__fish_seen_subcommand_from $paged_commands" -l no-pager -d "Disable pager" complete -c stup -n "__fish_seen_subcommand_from $paged_commands" -l pager -d "Use pager" -# store category directory and complete from the contained category file -cat "$HOME/.config/stup.conf" | read -d = -l _ category_dir +# complete from category file complete -c stup -n "__fish_seen_subcommand_from $cat_commands" -s c -l category -a "(cat $category_dir/categories.conf)" complete -c stup -n "__fish_seen_subcommand_from $name_cat_commands" -l category-name From 165a34bb1684421cba8dc782c55bbc9d27faed35 Mon Sep 17 00:00:00 2001 From: Niam Patel Date: Sun, 17 Jan 2021 22:35:44 +0000 Subject: [PATCH 3/6] move fish completion file --- completions/{__stup_complete.fish => stup_complete.fish} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename completions/{__stup_complete.fish => stup_complete.fish} (100%) diff --git a/completions/__stup_complete.fish b/completions/stup_complete.fish similarity index 100% rename from completions/__stup_complete.fish rename to completions/stup_complete.fish From d247e2666093a2a50b5f74f356d56a4b4c59e0e3 Mon Sep 17 00:00:00 2001 From: Niam Patel Date: Sun, 17 Jan 2021 23:15:20 +0000 Subject: [PATCH 4/6] maintain note option description for default complete --- completions/stup_complete.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/stup_complete.fish b/completions/stup_complete.fish index 5e82ebf..1ebfa47 100644 --- a/completions/stup_complete.fish +++ b/completions/stup_complete.fish @@ -22,7 +22,7 @@ complete -c stup -n "not __fish_seen_subcommand_from $commands" -x -a "$commands # default `add` behaviour with no subcommands complete -c stup -n "not __fish_seen_subcommand_from $commands" -s "@" -l at -d "Note timestamp" complete -c stup -n "not __fish_seen_subcommand_from $commands" -s c -l category -a "(cat $category_dir/categories.conf)" -complete -c stup -n "not __fish_seen_subcommand_from $commands" -s n -l note +complete -c stup -n "not __fish_seen_subcommand_from $commands" -s n -l note -d "Note content" # version and help complete -c stup -s v -l version -d "Print current version" From b948f9d8f3914e60de954bc00a29b8ef72f88e06 Mon Sep 17 00:00:00 2001 From: Niam Patel Date: Sun, 17 Jan 2021 23:42:07 +0000 Subject: [PATCH 5/6] add default category directory --- completions/stup_complete.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completions/stup_complete.fish b/completions/stup_complete.fish index 1ebfa47..4728a13 100644 --- a/completions/stup_complete.fish +++ b/completions/stup_complete.fish @@ -10,8 +10,8 @@ set -l cat_commands show add edit copy log search set-category rename-category set -l name_cat_commands add-category rename-category set -l desc_cat_commands add-category set-category -# read category file path from config -cat "$HOME/.config/stup.conf" | read -d = -l _ category_dir +# read category file path from config. default to ~/stup +cat "$HOME/.config/stup.conf" 2> /dev/null | read -d = -l _ category_dir ; or set -l category_dir "$HOME/stup" # disable file completions complete -c stup -f From 7066e9ac4c795515fe0e5a07778c094ae5605fdc Mon Sep 17 00:00:00 2001 From: Niam Patel Date: Mon, 18 Jan 2021 10:42:22 +0000 Subject: [PATCH 6/6] resolve issues: command names, spacing and use of XDG_CONFIG_HOME --- completions/stup_complete.fish | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/completions/stup_complete.fish b/completions/stup_complete.fish index 4728a13..4c325e4 100644 --- a/completions/stup_complete.fish +++ b/completions/stup_complete.fish @@ -1,17 +1,17 @@ #!/usr/bin/env fish set -l times week month year previous-week previous-month previous-year -set -l commands show add edit copy log search add-category list-category set-category order-category rename-category usage +set -l commands show add edit copy log search add-category list-categories set-category-description order-categories rename-category usage version set -l paged_commands log usage set -l note_commands add -set -l dated_commands show add edit +set -l dated_commands show add edit set -l ranged_commands copy log search -set -l cat_commands show add edit copy log search set-category rename-category +set -l cat_commands show add edit copy log search set-category-description rename-category set -l name_cat_commands add-category rename-category -set -l desc_cat_commands add-category set-category +set -l desc_cat_commands add-category set-category-description # read category file path from config. default to ~/stup -cat "$HOME/.config/stup.conf" 2> /dev/null | read -d = -l _ category_dir ; or set -l category_dir "$HOME/stup" +cat "$XDG_CONFIG_HOME/stup.conf" 2> /dev/null | read -d = -l _ category_dir ; or set -l category_dir "$HOME/stup" # disable file completions complete -c stup -f @@ -29,7 +29,7 @@ complete -c stup -s v -l version -d "Print current version" complete -c stup -s h -l help # @/at options -complete -c stup -n "__fish_seen_subcommand_from $dated_commands" -s "@" -l at -d "Note timestamp" +complete -c stup -n "__fish_seen_subcommand_from $dated_commands" -s "@" -l at -d "Note timestamp" # from/to options complete -c stup -n "__fish_seen_subcommand_from $ranged_commands" -s f -l from