diff --git a/completions/capistrano.completion.sh b/completions/capistrano.completion.sh index 9d4f7cb5e..40362765b 100644 --- a/completions/capistrano.completion.sh +++ b/completions/capistrano.completion.sh @@ -4,11 +4,10 @@ export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} function _omb_completion_cap { - if [ -f Capfile ]; then - recent=`ls -t .cap_tasks~ Capfile **/*.cap 2> /dev/null | head -n 1` + if [[ -f Capfile ]]; then + local recent=$(ls -t .cap_tasks~ Capfile **/*.cap 2> /dev/null | head -n 1) if [[ $recent != '.cap_tasks~' ]]; then - cap --version | grep 'Capistrano v2.' > /dev/null - if [ $? -eq 0 ]; then + if cap --version | grep 'Capistrano v2.' > /dev/null; then # Capistrano 2.x cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~ else @@ -16,7 +15,7 @@ function _omb_completion_cap { cap --all --tasks | cut -d " " -f 2 > .cap_tasks~ fi fi - COMPREPLY=($(compgen -W "`cat .cap_tasks~`" -- ${COMP_WORDS[COMP_CWORD]})) + COMPREPLY=($(compgen -W '$(< .cap_tasks)' -- "${COMP_WORDS[COMP_CWORD]}")) return 0 fi } diff --git a/completions/homesick.completion.sh b/completions/homesick.completion.sh index 17eeb12ab..577b644c1 100644 --- a/completions/homesick.completion.sh +++ b/completions/homesick.completion.sh @@ -3,54 +3,54 @@ # # The homebrew bash completion script was used as inspiration. # Originally from https://github.com/liborw/homesick-completion +# https://github.com/liborw/homesick-completion/blob/904d121d1b8f81629f473915a10c9144fdd416dc/homesick_bash_completion.sh _omb_completion_homesick() { - local cur="${COMP_WORDS[COMP_CWORD]}" + local cur=${COMP_WORDS[COMP_CWORD]} local options="--skip --force --pretend --quiet" local actions="cd clone commit destroy diff generate help list open pull push rc show_path status symlink track unlink version" local repos=$(\ls ~/.homesick/repos) # Subcommand list - [[ ${COMP_CWORD} -eq 1 ]] && { - COMPREPLY=( $(compgen -W "${options} ${actions}" -- ${cur}) ) + if ((COMP_CWORD == 1)); then + COMPREPLY=( $(compgen -W "${options} ${actions}" -- "$cur") ) return - } + fi # Find the first non-switch word local prev_index=1 - local prev="${COMP_WORDS[prev_index]}" + local prev=${COMP_WORDS[prev_index]} while [[ $prev == -* ]]; do - prev_index=$((++prev_index)) - prev="${COMP_WORDS[prev_index]}" + ((++prev_index)) + prev=${COMP_WORDS[prev_index]} done # Find the number of non-"--" commands local num=0 - for word in ${COMP_WORDS[@]} - do + for word in "${COMP_WORDS[@]}"; do if [[ $word != -* ]]; then - num=$((++num)) + ((++num)) fi done - case "$prev" in + case $prev in # Commands that take a castle cd|commit|destroy|diff|open|pull|push|rc|show_path|status|symlink|unlink) - COMPREPLY=( $(compgen -W "${repos}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${repos}" -- "$cur") ) return ;; # Commands that take command help) - COMPREPLY=( $(compgen -W "${actions}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${actions}" -- "$cur") ) return ;; # Track command take file and repo track) - if [[ "$num" -eq 2 ]]; then - COMPREPLY=( $(compgen -X -f ${cur}) ) - elif [[ "$num" -ge 3 ]]; then - COMPREPLY=( $(compgen -W "${repos}" -- ${cur}) ) + if ((num == 2)); then + COMPREPLY=( $(compgen -X -f "$cur") ) + elif ((num >= 3)); then + COMPREPLY=( $(compgen -W "${repos}" -- "$cur") ) fi return ;; @@ -58,4 +58,3 @@ _omb_completion_homesick() } complete -o bashdefault -o default -F _omb_completion_homesick homesick - diff --git a/completions/rake.completion.sh b/completions/rake.completion.sh index 5bb57f729..f13963137 100644 --- a/completions/rake.completion.sh +++ b/completions/rake.completion.sh @@ -4,12 +4,12 @@ export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} function _omb_completion_rake { - if [ -f Rakefile ]; then - recent=`ls -t .rake_tasks~ Rakefile **/*.rake 2> /dev/null | head -n 1` + if [[ -f Rakefile ]]; then + local recent=$(ls -t .rake_tasks~ Rakefile **/*.rake 2> /dev/null | head -n 1) if [[ $recent != '.rake_tasks~' ]]; then rake --silent --tasks --all | cut -d " " -f 2 > .rake_tasks~ fi - COMPREPLY=($(compgen -W "`cat .rake_tasks~`" -- ${COMP_WORDS[COMP_CWORD]})) + COMPREPLY=($(compgen -W '$(< .rake_tasks~)' -- "${COMP_WORDS[COMP_CWORD]}")) return 0 fi } diff --git a/completions/sdkman.completion.sh b/completions/sdkman.completion.sh index a10d42354..6e25b5043 100644 --- a/completions/sdkman.completion.sh +++ b/completions/sdkman.completion.sh @@ -9,13 +9,12 @@ if ! declare -F __sdkman_build_version_csv &>/dev/null; then # sdkman/sdkman-cli". # https://github.com/sdkman/sdkman-cli/blob/19e5c081297d6a8d1ce8a8b54631bb3f8e8e861b/src/main/bash/sdkman-list.sh#L51 function __sdkman_build_version_csv() { - local candidate versions_csv - candidate="$1" - versions_csv="" - if [[ -d "${SDKMAN_CANDIDATES_DIR}/${candidate}" ]]; then + local candidate=$1 + local versions_csv="" + if [[ -d ${SDKMAN_CANDIDATES_DIR}/${candidate} ]]; then for version in $(find "${SDKMAN_CANDIDATES_DIR}/${candidate}" -maxdepth 1 -mindepth 1 \( -type l -o -type d \) -exec basename '{}' \; | sort -r); do - if [[ "$version" != 'current' ]]; then - versions_csv="${version},${versions_csv}" + if [[ $version != 'current' ]]; then + versions_csv=${version},${versions_csv} fi done versions_csv=${versions_csv%?} @@ -26,36 +25,36 @@ fi _omb_completion_sdkman() { - local CANDIDATES - local CANDIDATE_VERSIONS - + local cur=${COMP_WORDS[COMP_CWORD]} COMPREPLY=() - if [ $COMP_CWORD -eq 1 ]; then - COMPREPLY=( $(compgen -W "install uninstall rm list ls use current outdated version default selfupdate broadcast offline help flush" -- ${COMP_WORDS[COMP_CWORD]}) ) - elif [ $COMP_CWORD -eq 2 ]; then - case "${COMP_WORDS[COMP_CWORD-1]}" in + if ((COMP_CWORD == 1)); then + COMPREPLY=( $(compgen -W "install uninstall rm list ls use current outdated version default selfupdate broadcast offline help flush" -- "$cur") ) + elif ((COMP_CWORD == 2)); then + case ${COMP_WORDS[COMP_CWORD-1]} in "install" | "uninstall" | "rm" | "list" | "ls" | "use" | "current" | "outdated" ) - CANDIDATES=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ') - COMPREPLY=( $(compgen -W "$CANDIDATES" -- ${COMP_WORDS[COMP_CWORD]}) ) + local candidates + candidates=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ') + COMPREPLY=( $(compgen -W "$candidates" -- "$cur") ) ;; "offline" ) - COMPREPLY=( $(compgen -W "enable disable" -- ${COMP_WORDS[COMP_CWORD]}) ) + COMPREPLY=( $(compgen -W "enable disable" -- "$cur") ) ;; "selfupdate" ) - COMPREPLY=( $(compgen -W "force" -P "[" -S "]" -- ${COMP_WORDS[COMP_CWORD]}) ) + COMPREPLY=( $(compgen -W "force" -P "[" -S "]" -- "$cur") ) ;; "flush" ) - COMPREPLY=( $(compgen -W "candidates broadcast archives temp" -- ${COMP_WORDS[COMP_CWORD]}) ) + COMPREPLY=( $(compgen -W "candidates broadcast archives temp" -- "$cur") ) ;; *) ;; esac - elif [ $COMP_CWORD -eq 3 ]; then - case "${COMP_WORDS[COMP_CWORD-2]}" in + elif ((COMP_CWORD == 3)); then + case ${COMP_WORDS[COMP_CWORD-2]} in "install" | "uninstall" | "rm" | "use" | "default" ) - _omb_completion_sdkman__candidate_versions ${COMP_WORDS[COMP_CWORD-1]} - COMPREPLY=( $(compgen -W "$CANDIDATE_VERSIONS" -- ${COMP_WORDS[COMP_CWORD]}) ) + local candidate_versions + _omb_completion_sdkman__candidate_versions "${COMP_WORDS[COMP_CWORD-1]}" + COMPREPLY=( $(compgen -W "$candidate_versions" -- "$cur") ) ;; *) ;; @@ -66,21 +65,19 @@ _omb_completion_sdkman() } function _omb_completion_sdkman__candidate_versions { - - CANDIDATE_LOCAL_VERSIONS=$(_omb_completion_sdkman__cleanup_local_versions $1) - if [ "$SDKMAN_OFFLINE_MODE" = "true" ]; then - CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS + local local_versions=$(_omb_completion_sdkman__cleanup_local_versions "$1") + if [[ $SDKMAN_OFFLINE_MODE = "true" ]]; then + candidate_versions=$local_versions else - CANDIDATE_ONLINE_VERSIONS="$(curl -s "${SDKMAN_SERVICE}/candidates/$1" | tr ',' ' ')" - CANDIDATE_VERSIONS="$(echo $CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS |sort | uniq ) " + local online_versions="$(curl -s "${SDKMAN_SERVICE}/candidates/$1" | tr ',' ' ')" + candidate_versions="$(echo $online_versions $local_versions |sort | uniq ) " fi } function _omb_completion_sdkman__cleanup_local_versions { - __sdkman_build_version_csv $1 - echo $CSV | tr ',' ' ' - + __sdkman_build_version_csv "$1" + tr ',' ' ' <<< "$CSV" } complete -F _omb_completion_sdkman sdk diff --git a/completions/ssh.completion.sh b/completions/ssh.completion.sh index 67cb07785..3bcb77562 100644 --- a/completions/ssh.completion.sh +++ b/completions/ssh.completion.sh @@ -4,29 +4,28 @@ export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} function _omb_completion_ssh { - local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" - if [[ ${CURRENT_PROMPT} == *@* ]] ; then - local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}" + local cur=${COMP_WORDS[COMP_CWORD]} + if [[ $cur == *@* ]] ; then + local -a options=(-P "${cur%%@*}@" -- "${cur#*@}") else - local OPTIONS=" -- ${CURRENT_PROMPT}" + local -a options=(-- "$cur") fi - # parse all defined hosts from .ssh/config - if [ -r "$HOME/.ssh/config" ]; then - COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) ) + if [[ -r $HOME/.ssh/config ]]; then + COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" "${options[@]}")) fi # parse all hosts found in .ssh/known_hosts - if [ -r "$HOME/.ssh/known_hosts" ]; then + if [[ -r $HOME/.ssh/known_hosts ]]; then if grep -v -q -e '^ ssh-rsa' "$HOME/.ssh/known_hosts" ; then - COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( awk '{print $1}' "$HOME/.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" ${OPTIONS}) ) + COMPREPLY+=($(compgen -W "$( awk '{print $1}' "$HOME/.ssh/known_hosts" | grep -v ^\| | cut -d, -f 1 | sed -e 's/\[//g' | sed -e 's/\]//g' | cut -d: -f1 | grep -v ssh-rsa)" "${options[@]}")) fi fi # parse hosts defined in /etc/hosts - if [ -r /etc/hosts ]; then - COMPREPLY=( ${COMPREPLY[@]} $(compgen -W "$( grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) ) + if [[ -r /etc/hosts ]]; then + COMPREPLY+=($(compgen -W "$( grep -v '^[[:space:]]*$' /etc/hosts | grep -v '^#' | awk '{for (i=2; i<=NF; i++) print $i}' )" "${options[@]}")) fi return 0