From e6572f4b8561c7f89daf8bc58e6758a4f4b65d96 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Sun, 1 Oct 2023 03:32:03 +0900 Subject: [PATCH] completions/{cap,homesick,rake,sdkman,ssh}: Change indentation and whitespaces --- completions/capistrano.completion.sh | 28 ++++----- completions/homesick.completion.sh | 90 ++++++++++++++-------------- completions/rake.completion.sh | 14 ++--- completions/ssh.completion.sh | 46 +++++++------- 4 files changed, 89 insertions(+), 89 deletions(-) diff --git a/completions/capistrano.completion.sh b/completions/capistrano.completion.sh index a91fa4e08..9d4f7cb5e 100644 --- a/completions/capistrano.completion.sh +++ b/completions/capistrano.completion.sh @@ -4,21 +4,21 @@ 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 [[ $recent != '.cap_tasks~' ]]; then - cap --version | grep 'Capistrano v2.' > /dev/null - if [ $? -eq 0 ]; then - # Capistrano 2.x - cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~ - else - # Capistrano 3.x - cap --all --tasks | cut -d " " -f 2 > .cap_tasks~ - fi - fi - COMPREPLY=($(compgen -W "`cat .cap_tasks~`" -- ${COMP_WORDS[COMP_CWORD]})) - return 0 + if [ -f Capfile ]; then + 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 + # Capistrano 2.x + cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~ + else + # Capistrano 3.x + cap --all --tasks | cut -d " " -f 2 > .cap_tasks~ + fi fi + COMPREPLY=($(compgen -W "`cat .cap_tasks~`" -- ${COMP_WORDS[COMP_CWORD]})) + return 0 + fi } complete -o default -o nospace -F _omb_completion_cap cap diff --git a/completions/homesick.completion.sh b/completions/homesick.completion.sh index 57b4ea187..17eeb12ab 100644 --- a/completions/homesick.completion.sh +++ b/completions/homesick.completion.sh @@ -6,55 +6,55 @@ _omb_completion_homesick() { - 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) + 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}) ) - return - } + # Subcommand list + [[ ${COMP_CWORD} -eq 1 ]] && { + COMPREPLY=( $(compgen -W "${options} ${actions}" -- ${cur}) ) + return + } - # Find the first non-switch word - local prev_index=1 - local prev="${COMP_WORDS[prev_index]}" - while [[ $prev == -* ]]; do - prev_index=$((++prev_index)) - prev="${COMP_WORDS[prev_index]}" - done + # Find the first non-switch word + local prev_index=1 + local prev="${COMP_WORDS[prev_index]}" + while [[ $prev == -* ]]; do + 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 - if [[ $word != -* ]]; then - num=$((++num)) - fi - done + # Find the number of non-"--" commands + local num=0 + for word in ${COMP_WORDS[@]} + do + if [[ $word != -* ]]; then + num=$((++num)) + fi + done - 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}) ) - return - ;; - # Commands that take command - help) - 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}) ) - fi - return - ;; - esac + 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}) ) + return + ;; + # Commands that take command + help) + 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}) ) + fi + return + ;; + esac } complete -o bashdefault -o default -F _omb_completion_homesick homesick diff --git a/completions/rake.completion.sh b/completions/rake.completion.sh index 0ee5cd872..5bb57f729 100644 --- a/completions/rake.completion.sh +++ b/completions/rake.completion.sh @@ -4,14 +4,14 @@ 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 [[ $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]})) - return 0 + if [ -f Rakefile ]; then + 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]})) + return 0 + fi } complete -o default -o nospace -F _omb_completion_rake rake diff --git a/completions/ssh.completion.sh b/completions/ssh.completion.sh index 479199631..67cb07785 100644 --- a/completions/ssh.completion.sh +++ b/completions/ssh.completion.sh @@ -4,32 +4,32 @@ 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/*@/}" - else - local OPTIONS=" -- ${CURRENT_PROMPT}" + local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" + if [[ ${CURRENT_PROMPT} == *@* ]] ; then + local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}" + else + local OPTIONS=" -- ${CURRENT_PROMPT}" + 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}) ) + fi + + # parse all hosts found in .ssh/known_hosts + 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}) ) 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}) ) + 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}) ) - fi - - # parse all hosts found in .ssh/known_hosts - 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}) ) - 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}) ) - fi - - return 0 + return 0 } complete -o default -o nospace -F _omb_completion_ssh ssh scp