Skip to content

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions completions/stup_complete.fish
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"
Copy link

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


# 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
Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no -f & -t, the same in the following lines

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"
Copy link

Choose a reason for hiding this comment

The 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"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--pager requires an argument (program to execute or false)


# 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