Skip to content

Commit 3d23576

Browse files
committed
- Implement full bash completion
1 parent 2e19d03 commit 3d23576

File tree

11 files changed

+276
-51
lines changed

11 files changed

+276
-51
lines changed

op.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
watch: filewatcher --immediate "**/*.{sh,yml}" "bashly generate"
22
#? watch files and regenerate script on change
33

4-
generate: bashly generate
4+
generate: bashly add comp function && bashly generate
55
#? regenerate script
66

77
test: docker-compose run --rm test

rush

Lines changed: 143 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,27 @@ rush_usage() {
2424
echo
2525
# :command.usage_commands
2626
printf "Repository Commands:\n"
27-
echo " add Register a local repository"
28-
echo " remove Unregister a local repository"
27+
echo " add Register a local repository"
28+
echo " remove Unregister a local repository"
2929
printf "\nGit Commands:\n"
30-
echo " clone Clone a GitHub package repository"
31-
echo " pull Git pull one or all repositories"
32-
echo " push Git push one or all repositories"
30+
echo " clone Clone a GitHub package repository"
31+
echo " pull Git pull one or all repositories"
32+
echo " push Git push one or all repositories"
3333
printf "\nConfig Commands:\n"
34-
echo " config Show or edit the configuration file"
35-
echo " default Set a default repository"
34+
echo " config Show or edit the configuration file"
35+
echo " default Set a default repository"
3636
printf "\nPackage Commands:\n"
37-
echo " get Install a package (default)"
38-
echo " undo Uninstall a package"
39-
echo " snatch Install a package from a remote repo"
40-
echo " copy Copy a package between local repositories"
41-
echo " info Show information about a package"
42-
echo " list Show packages in one or all repositories"
43-
echo " search Search in package names and info files"
44-
echo " edit Edit package files"
45-
echo " show Show package files"
37+
echo " get Install a package (default)"
38+
echo " undo Uninstall a package"
39+
echo " snatch Install a package from a remote repo"
40+
echo " copy Copy a package between local repositories"
41+
echo " info Show information about a package"
42+
echo " list Show packages in one or all repositories"
43+
echo " search Search in package names and info files"
44+
echo " edit Edit package files"
45+
echo " show Show package files"
46+
printf "\nInternal Commands:\n"
47+
echo " completions Generate bash completions"
4648
echo
4749

4850
if [[ -n $long_usage ]]; then
@@ -791,6 +793,31 @@ rush_show_usage() {
791793
fi
792794
}
793795

796+
# :command.usage
797+
rush_completions_usage() {
798+
if [[ -n $long_usage ]]; then
799+
printf "rush completions - Generate bash completions\n"
800+
echo
801+
else
802+
printf "rush completions - Generate bash completions\n"
803+
echo
804+
fi
805+
806+
printf "Usage:\n"
807+
printf " rush completions\n"
808+
printf " rush completions --help | -h\n"
809+
echo
810+
811+
if [[ -n $long_usage ]]; then
812+
printf "Options:\n"
813+
# :command.usage_fixed_flags
814+
echo " --help, -h"
815+
printf " Show this help\n"
816+
echo
817+
818+
fi
819+
}
820+
794821
# :command.inspect_args
795822
inspect_args() {
796823
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
@@ -990,6 +1017,41 @@ say() {
9901017
printf "%-20s | %s\n" "$(magenta "$1")" "$(bold "${*:2}")"
9911018
}
9921019

1020+
# :src/lib/send_completions.sh
1021+
send_completions() {
1022+
echo $'#!/usr/bin/env bash'
1023+
echo $''
1024+
echo $'# This bash completions script was generated by'
1025+
echo $'# completely (https://github.com/dannyben/completely)'
1026+
echo $'# Modifying it manually is not recommended'
1027+
echo $'_rush_completions() {'
1028+
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
1029+
echo $''
1030+
echo $' case "$COMP_LINE" in'
1031+
echo $' \'rush completions\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
1032+
echo $' \'rush default\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
1033+
echo $' \'rush remove\'*) COMPREPLY=($(compgen -W "--help --purge -h -p" -- "$cur")) ;;'
1034+
echo $' \'rush config\'*) COMPREPLY=($(compgen -W "--edit --help -e -h" -- "$cur")) ;;'
1035+
echo $' \'rush snatch\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
1036+
echo $' \'rush search\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
1037+
echo $' \'rush clone\'*) COMPREPLY=($(compgen -A directory -W "--default --help --ignore --name --shallow --ssh -d -h -i -n -s -w" -- "$cur")) ;;'
1038+
echo $' \'rush pull\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
1039+
echo $' \'rush push\'*) COMPREPLY=($(compgen -W "--all --help --message -a -h -m" -- "$cur")) ;;'
1040+
echo $' \'rush undo\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help -h" -- "$cur")) ;;'
1041+
echo $' \'rush copy\'*) COMPREPLY=($(compgen -W "$(rush list -s) --force --help -f -h" -- "$cur")) ;;'
1042+
echo $' \'rush info\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help -h" -- "$cur")) ;;'
1043+
echo $' \'rush list\'*) COMPREPLY=($(compgen -W "--help --simple -h -s" -- "$cur")) ;;'
1044+
echo $' \'rush edit\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help -h" -- "$cur")) ;;'
1045+
echo $' \'rush show\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help -h" -- "$cur")) ;;'
1046+
echo $' \'rush add\'*) COMPREPLY=($(compgen -A directory -W "--help -h" -- "$cur")) ;;'
1047+
echo $' \'rush get\'*) COMPREPLY=($(compgen -W "$(rush list -s) --clone --help -c -h" -- "$cur")) ;;'
1048+
echo $' \'rush\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help --version -h -v add clone completions config copy default edit get info list pull push remove search show snatch undo" -- "$cur")) ;;'
1049+
echo $' esac'
1050+
echo $'}'
1051+
echo $''
1052+
echo $'complete -F _rush_completions rush'
1053+
}
1054+
9931055
# :src/lib/warn.sh
9941056
warn() {
9951057
printf "%-20s | %s\n" "$(red "$1")" "$(red_bold "${*:2}")"
@@ -1568,6 +1630,12 @@ rush_show_command() {
15681630
fi
15691631
}
15701632

1633+
# :command.function
1634+
rush_completions_command() {
1635+
# :src/completions_command.sh
1636+
send_completions
1637+
}
1638+
15711639
# :command.parse_requirements
15721640
parse_requirements() {
15731641
# :command.fixed_flag_filter
@@ -1705,6 +1773,13 @@ parse_requirements() {
17051773
shift $#
17061774
;;
17071775

1776+
completions )
1777+
action="completions"
1778+
shift
1779+
rush_completions_parse_requirements "$@"
1780+
shift $#
1781+
;;
1782+
17081783
# :command.command_fallback
17091784
"" )
17101785
rush_usage
@@ -2723,6 +2798,50 @@ rush_show_parse_requirements() {
27232798
# :command.whitelist_filter
27242799
}
27252800

2801+
# :command.parse_requirements
2802+
rush_completions_parse_requirements() {
2803+
# :command.fixed_flag_filter
2804+
case "$1" in
2805+
--version | -v )
2806+
version_command
2807+
exit
2808+
;;
2809+
2810+
--help | -h )
2811+
long_usage=yes
2812+
rush_completions_usage
2813+
exit 1
2814+
;;
2815+
2816+
esac
2817+
# :command.environment_variables_filter
2818+
# :command.dependencies_filter
2819+
# :command.command_filter
2820+
action="completions"
2821+
# :command.required_args_filter
2822+
# :command.required_flags_filter
2823+
# :command.parse_requirements_while
2824+
while [[ $# -gt 0 ]]; do
2825+
key="$1"
2826+
case "$key" in
2827+
2828+
-* )
2829+
printf "invalid option: %s\n" "$key"
2830+
exit 1
2831+
;;
2832+
2833+
* )
2834+
# :command.parse_requirements_case
2835+
printf "invalid argument: %s\n" "$key"
2836+
exit 1
2837+
;;
2838+
2839+
esac
2840+
done
2841+
# :command.default_assignments
2842+
# :command.whitelist_filter
2843+
}
2844+
27262845
# :command.initialize
27272846
initialize() {
27282847
version="0.6.4"
@@ -2867,6 +2986,14 @@ run() {
28672986
rush_show_command
28682987
fi
28692988

2989+
elif [[ $action == "completions" ]]; then
2990+
if [[ ${args[--help]} ]]; then
2991+
long_usage=yes
2992+
rush_completions_usage
2993+
else
2994+
rush_completions_command
2995+
fi
2996+
28702997
elif [[ $action == "root" ]]; then
28712998
root_command
28722999
fi

setup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ fi
2323

2424
if [[ -n $compdir ]]; then
2525
echo "=== Installing autocompletions to $compdir"
26-
echo "complete -W '\$(rush list -s)' rush" | $sudo tee "${compdir}/rush" > /dev/null
26+
echo "eval \"\$(rush completions)\"" | $sudo tee "${compdir}/rush" > /dev/null
2727
else
2828
echo "=== Completion script was not installed"
2929
echo " To install it manually add this to your startup script:"
30-
echo " complete -W '\$(rush list -s)' rush"
30+
echo " eval \"\$(rush completions)\""
3131
fi
3232

3333
# Verify

src/bashly.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: rush
22
help: Personal package manager
33
version: 0.6.4
4+
completions: [$(rush list -s)]
45

56
environment_variables:
67
- name: rush_config
@@ -11,6 +12,7 @@ environment_variables:
1112
commands:
1213
- name: add
1314
short: a
15+
completions: [<directory>]
1416
group: Repository
1517
help: |-
1618
Register a local repository
@@ -49,6 +51,7 @@ commands:
4951
- rush remove bobby --purge
5052

5153
- name: clone
54+
completions: [<directory>]
5255
group: Git
5356
help: |-
5457
Clone a GitHub package repository
@@ -153,6 +156,7 @@ commands:
153156

154157
- name: get
155158
short: g
159+
completions: [$(rush list -s)]
156160
group: Package
157161
help: |-
158162
Install a package
@@ -187,6 +191,7 @@ commands:
187191

188192
- name: undo
189193
short: u
194+
completions: [$(rush list -s)]
190195
help: |-
191196
Uninstall a package
192197
This command runs the undo script in the package directory.
@@ -221,6 +226,7 @@ commands:
221226
- rush snatch james/other-rush-repo python
222227

223228
- name: copy
229+
completions: [$(rush list -s)]
224230
help: Copy a package between local repositories
225231

226232
args:
@@ -253,6 +259,7 @@ commands:
253259

254260
- name: info
255261
short: i
262+
completions: [$(rush list -s)]
256263
help: |-
257264
Show information about a package
258265
This command shows the info file from the package directory.
@@ -302,6 +309,7 @@ commands:
302309

303310
- name: edit
304311
short: e
312+
completions: [$(rush list -s)]
305313
help: Edit package files
306314

307315
args:
@@ -315,6 +323,7 @@ commands:
315323
Default: main
316324
317325
- name: show
326+
completions: [$(rush list -s)]
318327
help: Show package files
319328

320329
args:
@@ -324,3 +333,8 @@ commands:
324333

325334
- name: file
326335
help: File to show (show all if not specified).
336+
337+
- name: completions
338+
group: Internal
339+
help: |-
340+
Generate bash completions

src/completions_command.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
send_completions

src/lib/send_completions.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
send_completions() {
2+
echo $'#!/usr/bin/env bash'
3+
echo $''
4+
echo $'# This bash completions script was generated by'
5+
echo $'# completely (https://github.com/dannyben/completely)'
6+
echo $'# Modifying it manually is not recommended'
7+
echo $'_rush_completions() {'
8+
echo $' local cur=${COMP_WORDS[COMP_CWORD]}'
9+
echo $''
10+
echo $' case "$COMP_LINE" in'
11+
echo $' \'rush completions\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
12+
echo $' \'rush default\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
13+
echo $' \'rush remove\'*) COMPREPLY=($(compgen -W "--help --purge -h -p" -- "$cur")) ;;'
14+
echo $' \'rush config\'*) COMPREPLY=($(compgen -W "--edit --help -e -h" -- "$cur")) ;;'
15+
echo $' \'rush snatch\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
16+
echo $' \'rush search\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
17+
echo $' \'rush clone\'*) COMPREPLY=($(compgen -A directory -W "--default --help --ignore --name --shallow --ssh -d -h -i -n -s -w" -- "$cur")) ;;'
18+
echo $' \'rush pull\'*) COMPREPLY=($(compgen -W "--help -h" -- "$cur")) ;;'
19+
echo $' \'rush push\'*) COMPREPLY=($(compgen -W "--all --help --message -a -h -m" -- "$cur")) ;;'
20+
echo $' \'rush undo\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help -h" -- "$cur")) ;;'
21+
echo $' \'rush copy\'*) COMPREPLY=($(compgen -W "$(rush list -s) --force --help -f -h" -- "$cur")) ;;'
22+
echo $' \'rush info\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help -h" -- "$cur")) ;;'
23+
echo $' \'rush list\'*) COMPREPLY=($(compgen -W "--help --simple -h -s" -- "$cur")) ;;'
24+
echo $' \'rush edit\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help -h" -- "$cur")) ;;'
25+
echo $' \'rush show\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help -h" -- "$cur")) ;;'
26+
echo $' \'rush add\'*) COMPREPLY=($(compgen -A directory -W "--help -h" -- "$cur")) ;;'
27+
echo $' \'rush get\'*) COMPREPLY=($(compgen -W "$(rush list -s) --clone --help -c -h" -- "$cur")) ;;'
28+
echo $' \'rush\'*) COMPREPLY=($(compgen -W "$(rush list -s) --help --version -h -v add clone completions config copy default edit get info list pull push remove search show snatch undo" -- "$cur")) ;;'
29+
echo $' esac'
30+
echo $'}'
31+
echo $''
32+
echo $'complete -F _rush_completions rush'
33+
}

test/approvals/rush

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@ Usage:
66
rush --version | -v
77

88
Repository Commands:
9-
add Register a local repository
10-
remove Unregister a local repository
9+
add Register a local repository
10+
remove Unregister a local repository
1111

1212
Git Commands:
13-
clone Clone a GitHub package repository
14-
pull Git pull one or all repositories
15-
push Git push one or all repositories
13+
clone Clone a GitHub package repository
14+
pull Git pull one or all repositories
15+
push Git push one or all repositories
1616

1717
Config Commands:
18-
config Show or edit the configuration file
19-
default Set a default repository
18+
config Show or edit the configuration file
19+
default Set a default repository
2020

2121
Package Commands:
22-
get Install a package (default)
23-
undo Uninstall a package
24-
snatch Install a package from a remote repo
25-
copy Copy a package between local repositories
26-
info Show information about a package
27-
list Show packages in one or all repositories
28-
search Search in package names and info files
29-
edit Edit package files
30-
show Show package files
22+
get Install a package (default)
23+
undo Uninstall a package
24+
snatch Install a package from a remote repo
25+
copy Copy a package between local repositories
26+
info Show information about a package
27+
list Show packages in one or all repositories
28+
search Search in package names and info files
29+
edit Edit package files
30+
show Show package files
31+
32+
Internal Commands:
33+
completions Generate bash completions

0 commit comments

Comments
 (0)