Skip to content

Commit a474dcf

Browse files
authored
Merge pull request #71 from toshi0383/bash-completion
Bash completion
2 parents 3155be9 + 592ff96 commit a474dcf

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## master
2+
##### Enhancement
3+
* Bash completion [#71](https://github.com/toshi384/cmdshelf/pull/71)
4+
[Toshihiro Suzuki](https://github.com/toshi0383)
5+
16
## 0.9.5
27
##### Enhancement
38
* short names for subcommands [#68](https://github.com/toshi384/cmdshelf/pull/68)

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,33 @@ cmdshelf is a new way of scripting.😎
3333

3434
You can see detailed document [here](doc/getting-started.md), or type `man cmdshelf`.
3535

36-
# Pro tip: set aliases
36+
# Pro tip
37+
## set aliases
3738
Put this in your `.bashrc`. You don't have to type "cmdshelf" each time.
3839
```
3940
alias run='cmdshelf run'
4041
alias list='cmdshelf list'
4142
```
4243

44+
## Use auto bash-completion
45+
In case of binary install suggested [here](#installsh), `cmdshelf-completion.bash` is copied under `/usr/local/etc/bash-completion.d`. All you have to do is to make bash be aware of that file.
46+
47+
Either put this in your `~/.bashrc`,
48+
```shell
49+
source /usr/local/etc/bash_completion.d/cmdshelf-completion.bash
50+
```
51+
52+
or install `bash-completion` via homebrew. (Personally I've never managed it to work correctly.)
53+
54+
If you build from source either via `Mint` or manually, then you first have to copy or symlink it manually.
55+
```shell
56+
# copy
57+
cp Sources/Scripts/cmdshelf-completion.bash /usr/local/etc/bash-completion.d/
58+
59+
# or simlink
60+
ln -s Sources/Scripts/cmdshelf-completion.bash /usr/local/etc/bash-completion.d/cmdshelf-completion.bash
61+
```
62+
4363
# Install
4464
## macOS
4565
### install.sh
@@ -58,7 +78,7 @@ mint install toshi0383/cmdshelf
5878

5979
Please build from source-code if `install.sh` didn't work.
6080

61-
- Clone this repo and run `swift build -c release`.
81+
- Clone this repo and run `swift build -c release`.
6282
- Executable will be created at `.build/release/cmdshelf`.
6383
- `mv .build/release/cmdshelf /usr/local/bin/`
6484

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Bash completion script for cmdshelf.
2+
3+
_cmdshelf() {
4+
local commands command cur prev
5+
commands="blob cat list ls remote run update"
6+
7+
command="${COMP_WORDS[1]}"
8+
cur="${COMP_WORDS[COMP_CWORD]}"
9+
prev="${COMP_WORDS[COMP_CWORD-1]}"
10+
11+
if [ $COMP_CWORD == 1 ]
12+
then
13+
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
14+
return 0
15+
fi
16+
17+
if [ $COMP_CWORD == 2 -a "${command}" == help ]
18+
then
19+
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
20+
return 0
21+
fi
22+
23+
case "${command}" in
24+
blob|remote)
25+
COMPREPLY=($(compgen -W 'add list remove' -- ${cur}))
26+
return 0
27+
;;
28+
list|ls)
29+
COMPREPLY=($(compgen -W '--path' -- ${cur}))
30+
return 0
31+
;;
32+
run)
33+
COMPREPLY=($(compgen -W "$(cmdshelf list | grep -v ':')" -- ${cur}))
34+
return 0
35+
;;
36+
esac
37+
}
38+
39+
complete -F _cmdshelf cmdshelf

0 commit comments

Comments
 (0)