Skip to content

Commit

Permalink
completions/{cap,homesick,rake,sdkman,ssh}: Change indentation and wh…
Browse files Browse the repository at this point in the history
…itespaces
  • Loading branch information
akinomyoga committed Sep 30, 2023
1 parent 09ffba8 commit e6572f4
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 89 deletions.
28 changes: 14 additions & 14 deletions completions/capistrano.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
90 changes: 45 additions & 45 deletions completions/homesick.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions completions/rake.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
46 changes: 23 additions & 23 deletions completions/ssh.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e6572f4

Please sign in to comment.