Merge pull request #50 from timakro/pr-bash-completion

Add bash completion script
This commit is contained in:
Gregory 2021-08-28 17:43:39 -04:00 committed by GitHub
commit 90e78ba92d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View file

@ -48,7 +48,7 @@ handlr launch x-scheme-handler/https -- https://google.ca
- Far easier to use with simple commands like `get`, `set`, `list` - Far easier to use with simple commands like `get`, `set`, `list`
- Can operate on extensions, **no need to look up or remember mime types** - Can operate on extensions, **no need to look up or remember mime types**
- useful for common tasks like setting a handler for png/docx/etc files - useful for common tasks like setting a handler for png/docx/etc files
- Superb autocomplete (currently just fish), including mimes, extensions, and `.desktop` files - Superb autocomplete (currently fish, zsh and bash), including mimes, extensions, and `.desktop` files
- Optional json output for scripting - Optional json output for scripting
- Properly supports `Terminal=true` entries - Properly supports `Terminal=true` entries
@ -109,7 +109,7 @@ cargo install handlr
### Binaries ### Binaries
1. Download the latest [release binary](https://github.com/chmln/handlr/releases) and put it somewhere in `$PATH` 1. Download the latest [release binary](https://github.com/chmln/handlr/releases) and put it somewhere in `$PATH`
2. Download completions: 2. Download completions for fish:
```sh ```sh
curl https://raw.githubusercontent.com/chmln/handlr/master/completions/handlr.fish --create-dirs -o ~/.config/fish/completions/handlr.fish curl https://raw.githubusercontent.com/chmln/handlr/master/completions/handlr.fish --create-dirs -o ~/.config/fish/completions/handlr.fish
``` ```

34
completions/handlr vendored Normal file
View file

@ -0,0 +1,34 @@
_handlr()
{
local cur prev words cword
_init_completion || return
if ((cword == 1)); then
COMPREPLY=($(compgen -W 'get help launch list open set unset' -- "$cur"))
else
case ${words[1]} in
set | add)
if ((cword == 2)); then
COMPREPLY=($(compgen -W '$(handlr autocomplete -m)' -- "$cur"))
elif ((cword == 3)); then
COMPREPLY=($(compgen -W '$(handlr autocomplete -d | cut -f1)' -- "$cur"))
fi
;;
open)
_filedir
;;
unset | get)
COMPREPLY=($(compgen -W '$(handlr autocomplete -m)' -- "$cur"))
;;
launch)
if ((cword == 2)); then
COMPREPLY=($(compgen -W '$(handlr autocomplete -m)' -- "$cur"))
else
_filedir
fi
;;
esac
fi
}
complete -F _handlr handlr