diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 775a49bb..967263ab 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,7 @@ v4.7.0 * Removed ``bin/todo``. It is no longer requierd, as the entry point generated by setuptools no longer has performance issues. +* Added shell completions for fish. v4.6.0 ------ diff --git a/contrib/completion/fish/todo.fish b/contrib/completion/fish/todo.fish new file mode 100644 index 00000000..6728ab08 --- /dev/null +++ b/contrib/completion/fish/todo.fish @@ -0,0 +1,34 @@ +_TODO_COMPLETE=fish_source todo | source + +function __fish_todo_complete_categories + set -l python (__fish_anypython) || return + todo --porcelain list | $python -c " +import json +import sys +events = json.load(sys.stdin) +categories = set() +for event in events: + for category in event['categories']: + categories.add(category) +print('\n'.join(categories)) +" +end +complete -c todo -n "__fish_seen_subcommand_from list" -x -s c -l category -a "(__fish_todo_complete_categories)" + +function __fish_todo_complete_statuses + set -l statuses NEEDS-ACTION CANCELLED COMPLETED IN-PROCESS ANY + set -l token (commandline -t) + + if string match -qr ^-s -- $token + set token (string sub -s 3 -- $token) + end + + set -l complete (string split , -- $token)[1..-2] + + for s in $statuses + if ! string match -q -- $s $complete + string join -- , $complete $s + end + end +end +complete -c todo -n "__fish_seen_subcommand_from list" -x -s s -l status -a "(__fish_todo_complete_statuses)" diff --git a/docs/source/install.rst b/docs/source/install.rst index e5eec170..9d8e5593 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -73,6 +73,16 @@ file ``contrib/autocompletion/zsh/_todo`` to any directory in your ``$fpath``. Typically ``/usr/local/share/zsh/site-functions/`` is used for system-wide installations. +fish autocompletion (optional) +------------------------------ + +Basic command completion for fish is provided in the contrib ``contrib`` +directory. It uses the completion rules generated by ``click`` as a base and +defines some improvements on top of it. To use the completion, copy the file to +any directory read by fish, this is typically +``$XDG_CONFIG_HOME/fish/completions`` for user-specific files and something +like ``/usr/share/fish/vendor_completions.d`` for system-wide files. + Requirements ------------