Skip to content

Commit

Permalink
Use bash parameter expansion.
Browse files Browse the repository at this point in the history
I've updated this so it cleverly uses bash parameter expansion to conditionally include the current word and a space only if it starts with a hyphen.
  • Loading branch information
Montana authored Feb 8, 2024
1 parent badf024 commit 3ac513c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions autocomplete/bash_autocomplete
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#! /bin/bash
#!/bin/bash

_step_cli_bash_autocomplete() {
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == "-"* ]]; then
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
else
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
local cur="${COMP_WORDS[COMP_CWORD]}"
local opts

opts=$("${COMP_WORDS[@]:0:$COMP_CWORD}" "${cur:+$cur }--generate-bash-completion")

COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
}

complete -o bashdefault -o default -o nospace -F _step_cli_bash_autocomplete step

0 comments on commit 3ac513c

Please sign in to comment.