Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
45cd3d5
Fix fish completion by escaping characters
superatomic May 1, 2022
c4cfc4d
Prevent files from displaying in fish autocomplete
superatomic May 1, 2022
6cfe15a
Require a filepath after `-r` in fish autocomplete
superatomic May 1, 2022
a839565
Make fish-shell autocompletion smarter
superatomic May 5, 2022
2dc6b41
Remove redundant options in fish completion
superatomic May 5, 2022
286bba2
Remove quotes around `__fish_use_subcommand`
superatomic Jun 23, 2022
10ea344
Don't explicitly loop and echo in __tldr_get_files
superatomic Jun 23, 2022
3d04317
Don't explicitly remove duplicate `$cmpl` args
superatomic Jun 23, 2022
45fe27f
Format options' `complete` lines to align them
superatomic Jun 23, 2022
d203a19
Prevent completing paths if `~/.tldrc` is missing
superatomic Jun 23, 2022
3e1ebe6
Add fish completion for the `--list` option
superatomic Jun 23, 2022
1e56753
Add completion for `--linux`, `--osx`, & `--sunos`
superatomic Jun 23, 2022
213980d
Don't directly specify the values for `--platform`
superatomic Jun 23, 2022
8e0a4d7
Only autocomplete `-v` if it isn't already present
superatomic Jun 23, 2022
bfd2e99
Expand CHANGELOG with changes to fish completion
superatomic Jun 24, 2022
8e8a8f4
Don't suggest standalone options when others exist
superatomic Jun 25, 2022
535bc86
Refrain from referring to help as "this help"
superatomic Jun 25, 2022
d376f00
Make "purpose" plural by changing it to "purposes"
superatomic Jun 25, 2022
215160b
Remove most invalid suggestions of option pairings
superatomic Jun 26, 2022
cdb26f7
Improve completion behavior when using `--render`
superatomic Jun 26, 2022
81a5ca4
Make indentation consistent
superatomic Jun 26, 2022
141d83c
Remove incorrect required parameter completion
superatomic Jun 26, 2022
e2a8f05
Use `nor` instead of `and` in function name
superatomic Jun 27, 2022
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Deprecated features will be kept for any following maintenance release, and
will be removed after two major releases.

## [Unreleased]
### Added
- Add fish completion for `--list`, `--linux`, `--osx`, and `--sunos` flags
### Fixed
- Fix fish completion not escaping characters
- Make fish completion reflect actual usage of `tldr` better

## v1.4.3 - 2022-04-11
### Fixed
Expand Down
58 changes: 46 additions & 12 deletions autocomplete/complete.fish
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
complete -c tldr -xf -s v -d "print verbose output"
complete -c tldr -xf -l version -d "print version and exit"
complete -c tldr -xf -s h -l help -d "print this help and exit"
complete -c tldr -xf -s u -l update -d "update local database"
complete -c tldr -xf -s c -l clear-cache -d "clear local database"
complete -c tldr -rf -f -s p -l platform -a "linux osx sunos common" -d "select platform, supported are linux / osx / sunos / common"
complete -c tldr -r -s r -l render -a PATH -d "render a local page for testing purpose"
function __tldr_not_contain_standalone_opt
__fish_not_contain_opt -s v
and __fish_not_contain_opt version
and __fish_not_contain_opt -s l list
and __fish_not_contain_opt -s h help
and __fish_not_contain_opt -s u update
and __fish_not_contain_opt -s c clear-cache
end

function __tldr_no_os_choice_opt
__fish_not_contain_opt linux osx sunos
and __fish_not_contain_opt -s r render
and __tldr_not_contain_standalone_opt
end

function __tldr_no_os_choice_opt_nor_p
__tldr_no_os_choice_opt
and __fish_not_contain_opt -s p platform
end

function __tldr_positional
__fish_use_subcommand
and __tldr_not_contain_standalone_opt
end

function __tldr_positional_no_os
__tldr_positional
and __fish_not_contain_opt linux osx sunos
and __fish_not_contain_opt -s p platform
end

complete -c tldr -f -n "__fish_not_contain_opt -s v" -s v -d "print verbose output"
complete -c tldr -f -n __fish_is_first_arg -l version -d "print version and exit"
complete -c tldr -f -n __fish_is_first_arg -s l -l list -d "list all entries in the local database"
complete -c tldr -f -n __fish_is_first_arg -s h -l help -d "print help and exit"
complete -c tldr -f -n __fish_is_first_arg -s u -l update -d "update local database"
complete -c tldr -f -n __fish_is_first_arg -s c -l clear-cache -d "clear local database"
complete -c tldr -x -n __tldr_no_os_choice_opt -s p -l platform -d "select platform" -a "linux osx sunos common"
complete -c tldr -f -n __tldr_no_os_choice_opt_nor_p -l linux -d "show command page for Linux"
complete -c tldr -f -n __tldr_no_os_choice_opt_nor_p -l osx -d "show command page for macOS"
complete -c tldr -f -n __tldr_no_os_choice_opt_nor_p -l sunos -d "show command page for SunOS"
complete -c tldr -rF -n __tldr_positional_no_os -s r -l render -d "render a local page for testing purposes"

function __tldr_get_files
set -l files (basename -s .md (find $HOME/.tldrc/tldr/pages/$argv[1] -name '*.md'))
for f in $files
echo $f
end
basename -s .md (find $HOME/.tldrc/tldr/pages/$argv[1] -name '*.md') | string escape
end

if test -d "$HOME/.tldrc/tldr/pages"
Expand All @@ -25,7 +57,9 @@ if test -d "$HOME/.tldrc/tldr/pages"
set cmpl $cmpl (__tldr_get_files sunos)
end

complete -c tldr -a (echo $cmpl | sort | uniq)
complete -c tldr -f -a "$cmpl" -n __tldr_positional
end

complete -c tldr -f

functions -e __tldr_get_files