Skip to content
Open
Changes from 5 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-category set-category order-category rename-category usage
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

list-categor*ies*, set-category*-description*, order-categor*ies*

& version?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have had an issue with the stup version command returning Error: Unknown command "version" (using both fish and bash). This is why I originally didn't include the subcommand.

However it's functionality that should work and the error can be raised in a separate issue, so I'll add the subcommand.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ah, you’re right. I didn’t check if it works.

set -l paged_commands log usage
set -l note_commands add
set -l dated_commands show add edit
Comment thread
playonverbs marked this conversation as resolved.
Outdated
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

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

Choose a reason for hiding this comment

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

$XDG_CONFIG_HOME pls

stup/stup

Line 1119 in da6d23d

CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/stup.conf"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

$HOME/.config has been replaced with $XDG_CONFIG_HOME

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Then comes the issue when $XDG_CONFIG_HOME is not set…

Does fish not have that simple fallback system?


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

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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