-
Notifications
You must be signed in to change notification settings - Fork 31
Add fish shell completion script #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c6fae49
d03e244
165a34b
d247e26
b948f9d
7066e9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/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-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 ranged_commands copy log search | ||
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-description | ||
|
||
# read category file path from config. default to ~/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 | ||
|
||
# subcommands listed in $commands | ||
complete -c stup -n "not __fish_seen_subcommand_from $commands" -x -a "$commands" | ||
|
||
# default `add` behaviour with no subcommands | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default command can be changed in the config file, but respecting it could awfully increase complexity… (so I don’t require it) |
||
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 -d "Note content" | ||
|
||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no |
||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should complete dates, not ranges |
||
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 -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# 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 | ||
complete -c stup -n "__fish_seen_subcommand_from $desc_cat_commands" -l category-description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I won’t require
${XDG_CONFIG_HOME:-$HOME/.config}
(unless @iridakos does) since I’ve realised how fish makes this more verbose than other shells