Skip to content

Commit 87cfcd6

Browse files
superatomicjohnflavin
authored andcommitted
Various fixes and improvements to fish shell completion (#86)
Co-authored-by: John Flavin <[email protected]>
1 parent be56821 commit 87cfcd6

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Deprecated features will be kept for any following maintenance release, and
77
will be removed after two major releases.
88

99
## [Unreleased]
10+
### Added
11+
- Add fish completion for `--list`, `--linux`, `--osx`, and `--sunos` flags
12+
### Fixed
13+
- Fix fish completion not escaping characters
14+
- Make fish completion reflect actual usage of `tldr` better
1015

1116
## v1.4.3 - 2022-04-11
1217
### Fixed

autocomplete/complete.fish

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
1-
complete -c tldr -xf -s v -d "print verbose output"
2-
complete -c tldr -xf -l version -d "print version and exit"
3-
complete -c tldr -xf -s h -l help -d "print this help and exit"
4-
complete -c tldr -xf -s u -l update -d "update local database"
5-
complete -c tldr -xf -s c -l clear-cache -d "clear local database"
6-
complete -c tldr -rf -f -s p -l platform -a "linux osx sunos common" -d "select platform, supported are linux / osx / sunos / common"
7-
complete -c tldr -r -s r -l render -a PATH -d "render a local page for testing purpose"
1+
function __tldr_not_contain_standalone_opt
2+
__fish_not_contain_opt -s v
3+
and __fish_not_contain_opt version
4+
and __fish_not_contain_opt -s l list
5+
and __fish_not_contain_opt -s h help
6+
and __fish_not_contain_opt -s u update
7+
and __fish_not_contain_opt -s c clear-cache
8+
end
9+
10+
function __tldr_no_os_choice_opt
11+
__fish_not_contain_opt linux osx sunos
12+
and __fish_not_contain_opt -s r render
13+
and __tldr_not_contain_standalone_opt
14+
end
15+
16+
function __tldr_no_os_choice_opt_nor_p
17+
__tldr_no_os_choice_opt
18+
and __fish_not_contain_opt -s p platform
19+
end
20+
21+
function __tldr_positional
22+
__fish_use_subcommand
23+
and __tldr_not_contain_standalone_opt
24+
end
25+
26+
function __tldr_positional_no_os
27+
__tldr_positional
28+
and __fish_not_contain_opt linux osx sunos
29+
and __fish_not_contain_opt -s p platform
30+
end
31+
32+
complete -c tldr -f -n "__fish_not_contain_opt -s v" -s v -d "print verbose output"
33+
complete -c tldr -f -n __fish_is_first_arg -l version -d "print version and exit"
34+
complete -c tldr -f -n __fish_is_first_arg -s l -l list -d "list all entries in the local database"
35+
complete -c tldr -f -n __fish_is_first_arg -s h -l help -d "print help and exit"
36+
complete -c tldr -f -n __fish_is_first_arg -s u -l update -d "update local database"
37+
complete -c tldr -f -n __fish_is_first_arg -s c -l clear-cache -d "clear local database"
38+
complete -c tldr -x -n __tldr_no_os_choice_opt -s p -l platform -d "select platform" -a "linux osx sunos common"
39+
complete -c tldr -f -n __tldr_no_os_choice_opt_nor_p -l linux -d "show command page for Linux"
40+
complete -c tldr -f -n __tldr_no_os_choice_opt_nor_p -l osx -d "show command page for macOS"
41+
complete -c tldr -f -n __tldr_no_os_choice_opt_nor_p -l sunos -d "show command page for SunOS"
42+
complete -c tldr -rF -n __tldr_positional_no_os -s r -l render -d "render a local page for testing purposes"
843

944
function __tldr_get_files
10-
set -l files (basename -s .md (find $HOME/.tldrc/tldr/pages/$argv[1] -name '*.md'))
11-
for f in $files
12-
echo $f
13-
end
45+
basename -s .md (find $HOME/.tldrc/tldr/pages/$argv[1] -name '*.md') | string escape
1446
end
1547

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

28-
complete -c tldr -a (echo $cmpl | sort | uniq)
60+
complete -c tldr -f -a "$cmpl" -n __tldr_positional
2961
end
3062

63+
complete -c tldr -f
64+
3165
functions -e __tldr_get_files

0 commit comments

Comments
 (0)