Skip to content

Commit

Permalink
Merge pull request binpash#21 from gliargovas/add-shell-completion-files
Browse files Browse the repository at this point in the history
Add shell completion files
  • Loading branch information
angelhof authored Jun 20, 2023
2 parents 726b4f3 + b7dc773 commit 830aae2
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
20 changes: 20 additions & 0 deletions completions/README.md
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/
```
54 changes: 54 additions & 0 deletions completions/try.bash
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

0 comments on commit 830aae2

Please sign in to comment.