-
-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #480 from akinomyoga/comp_wordbreaks
completions/{ssh,rake,capistrano}: Do not rewrite `COMP_WORDBREAKS`
- Loading branch information
Showing
6 changed files
with
222 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
#! bash oh-my-bash.module | ||
# Bash completion support for Capistrano. | ||
|
||
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} | ||
_omb_module_require lib:omb-completion | ||
|
||
function _capcomplete { | ||
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 | ||
function _omb_completion_cap { | ||
local cur | ||
_omb_completion_reassemble_breaks : | ||
|
||
if [[ -f Capfile ]]; then | ||
local recent=$(ls -t .cap_tasks~ Capfile **/*.cap 2> /dev/null | head -n 1) | ||
if [[ $recent != '.cap_tasks~' ]]; then | ||
if cap --version | grep 'Capistrano v2.' > /dev/null; 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 '$(< .cap_tasks)' -- "$cur")) | ||
fi | ||
|
||
_omb_completion_resolve_breaks | ||
} | ||
|
||
complete -o default -o nospace -F _capcomplete cap | ||
complete -o default -o nospace -F _omb_completion_cap cap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#! bash oh-my-bash.module | ||
# Bash completion support for Rake, Ruby Make. | ||
|
||
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} | ||
_omb_module_require lib:omb-completion | ||
|
||
function _rakecomplete { | ||
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 | ||
function _omb_completion_rake { | ||
local cur | ||
_omb_completion_reassemble_breaks : | ||
|
||
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 '$(< .rake_tasks~)' -- "$cur")) | ||
fi | ||
|
||
_omb_completion_resolve_breaks | ||
} | ||
|
||
complete -o default -o nospace -F _rakecomplete rake | ||
complete -o default -o nospace -F _omb_completion_rake rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
#! bash oh-my-bash.module | ||
# Bash completion support for ssh. | ||
|
||
export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} | ||
|
||
function _sshcomplete { | ||
local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" | ||
if [[ ${CURRENT_PROMPT} == *@* ]] ; then | ||
local OPTIONS="-P ${CURRENT_PROMPT/@*/}@ -- ${CURRENT_PROMPT/*@/}" | ||
else | ||
local OPTIONS=" -- ${CURRENT_PROMPT}" | ||
_omb_module_require lib:omb-completion | ||
|
||
function _omb_completion_ssh { | ||
local cur | ||
_omb_completion_reassemble_breaks : | ||
|
||
if [[ $cur == *@* ]] ; then | ||
local -a options=(-P "${cur%%@*}@" -- "${cur#*@}") | ||
else | ||
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[@]}")) | ||
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+=($(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+=($(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 | ||
_omb_completion_resolve_breaks | ||
} | ||
|
||
complete -o default -o nospace -F _sshcomplete ssh scp | ||
complete -o default -o nospace -F _omb_completion_ssh ssh scp |
Oops, something went wrong.