Skip to content
Myr

Bash completion aliases (#638)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* alias support with bash completions * add cmdname to rootcmdname * remove print statement * add documentation for bash alias

authored by Rajat Jindal · committed by Eric Paris · parent 1a618fb · Browse files · 2 files+23 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+23 added−3 removed

  • other:+23 added−3 removed

2 files+23 added−3 removed

modified:bash_completions.go+9 added-3 removed
226 unmodified lines
227 if [[ -n ${last_command} ]]; then228 next_command="_${last_command}_${words[c]//:/__}"229 else230 if [[ $c -eq 0 ]]; then231 next_command="_$(basename "${words[c]//:/__}")"231 next_command="_%[1]s_root_command"232 else233 next_command="_${words[c]//:/__}"234 fi235 fi
12 unmodified lines
248 if [[ "${words[c]}" == -* ]]; then249 __%[1]s_handle_flag250 elif __%[1]s_contains_word "${words[c]}" "${commands[@]}"; then251 __%[1]s_handle_command252 elif [[ $c -eq 0 ]] && __%[1]s_contains_word "$(basename "${words[c]}")" "${commands[@]}"; then252 elif [[ $c -eq 0 ]]; then253 __%[1]s_handle_command254 else255 __%[1]s_handle_noun256 fi
203 unmodified lines
460 }461 commandName := cmd.CommandPath()462 commandName = strings.Replace(commandName, " ", "_", -1)463 commandName = strings.Replace(commandName, ":", "__", -1)464465 if cmd.Root() == cmd {466 buf.WriteString(fmt.Sprintf("_%s_root_command()\n{\n", commandName))467 } else {464 buf.WriteString(fmt.Sprintf("_%s()\n{\n", commandName))468 buf.WriteString(fmt.Sprintf("_%s()\n{\n", commandName))469 }470471 buf.WriteString(fmt.Sprintf(" last_command=%q\n", commandName))472 writeCommands(buf, cmd)473 writeFlags(buf, cmd)474 writeRequiredFlag(buf, cmd)
81 unmodified lines
modified:bash_completions.md+14 added
202 unmodified lines
203 COMPREPLY=( $( compgen -W "${kubectl_out}[*]" -- "$cur" ) )204 fi205}206```207# Using bash aliases for commands208209You can also configure the `bash aliases` for the commands and they will also support completions.210211```bash212alias aliasname=origcommand213complete -o default -F __start_origcommand aliasname214215# and now when you run `aliasname` completion will make216# suggestions as it did for `origcommand`.217218$) aliasname <tab><tab>219completion firstcommand secondcommand220```