forked from binpash/try
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request binpash#21 from gliargovas/add-shell-completion-files
Add shell completion files
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Shell completions | ||
|
||
This directory holds completions for the `bash` shell. | ||
|
||
You can apply completions locally by running: | ||
|
||
```Bash | ||
source try.bash | ||
``` | ||
|
||
Alternatively, to enable *try* shell completion by default, consider adding the following line to your `.bashrc`: | ||
```Bash | ||
source <path-to-your-script>/dothis-completion.bash | ||
``` | ||
|
||
To enable *try* shell completion for all users, | ||
consider copying the bash completion script to the `/etc/bash_completion.d/` directory: | ||
```Bash | ||
sudo cp try.bash /etc/bash_completion.d/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
_try() { | ||
local i cur prev opts cmds | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
cmd="" | ||
opts="" | ||
|
||
for i in ${COMP_WORDS[@]} | ||
do | ||
case "${i}" in | ||
try) | ||
cmd="try" | ||
;; | ||
|
||
*) | ||
;; | ||
esac | ||
done | ||
|
||
case "${cmd}" in | ||
try) | ||
opts="-n -y -v -h -D summary commit" | ||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then | ||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | ||
return 0 | ||
fi | ||
case "${prev}" in | ||
|
||
-D) | ||
COMPREPLY=($(compgen -d "${cur}")) | ||
return 0 | ||
;; | ||
|
||
commit) | ||
COMPREPLY=($(compgen -d "${cur}")) | ||
return 0 | ||
;; | ||
summary) | ||
COMPREPLY=($(compgen -d "${cur}")) | ||
return 0 | ||
;; | ||
*) | ||
COMPREPLY=() | ||
;; | ||
esac | ||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | ||
return 0 | ||
;; | ||
|
||
esac | ||
} | ||
|
||
complete -F _try -o bashdefault -o default try |