-
-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
completions/{ssh,rake,capistrano}: Do not rewrite COMP_WORDBREAKS
Fix #471
- Loading branch information
1 parent
cd8b4d2
commit 3da4bf6
Showing
4 changed files
with
81 additions
and
9 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
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 _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~)' -- "${COMP_WORDS[COMP_CWORD]}")) | ||
return 0 | ||
COMPREPLY=($(compgen -W '$(< .rake_tasks~)' -- "$cur")) | ||
fi | ||
|
||
_omb_completion_resolve_breaks | ||
} | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#! bash oh-my-bash.module | ||
# Copyright 2023 Koichi Murase. | ||
# | ||
# Helper functions for completions | ||
# | ||
|
||
## @fn _omb_completion_reassemble_breaks exclude | ||
## @param[in] $1 exclude Characters to exclude from COMP_WORDSBREAKS | ||
## @var[out] cur[0] Current word after reassembly | ||
## @var[out] cur[1] Part of ${cur[0]} that was originally in previous words | ||
## in COMP_WORDS. | ||
## @arr[out] COMPREPLY This functions empties the array COMPREPLY. | ||
function _omb_completion_reassemble_breaks { | ||
local exclude=$1 | ||
local line=$COMP_LINE point=$COMP_POINT | ||
local breaks=${COMP_WORDBREAKS//[\"\'$exclude]} | ||
|
||
COMPREPLY=() | ||
cur=("${COMP_WORDS[COMP_CWORD]}" '') | ||
|
||
local word rprefix= rword= | ||
for word in "${COMP_WORDS[@]::COMP_CWORD+1}"; do | ||
local space=${line%%"$word"*} | ||
if [[ $space == "$line" ]]; then | ||
# error: COMP_LINE does not contain enough words | ||
return 1 | ||
fi | ||
|
||
word=${word::point - ${#space}} | ||
if [[ $space || $rword == *["$breaks"] || $word == ["$breaks"]* ]]; then | ||
rprefix= | ||
rword=$word | ||
else | ||
rprefix=$rword | ||
rword+=$word | ||
fi | ||
|
||
line=${line:${#space}+${#word}} | ||
((point -= ${#space} + ${#word})) | ||
((point >= 0)) || break | ||
done | ||
|
||
cur=("$rword" "$rprefix") | ||
} | ||
|
||
## @fn _omb_completion_resolve_breaks | ||
## Adjust completions generated for the reassembled word | ||
## @var[out] cur[1] Prefix to remove set by _omb_completion_reassemble_breaks | ||
## @arr[out] COMPREPLY This functions empties the array COMPREPLY. | ||
function _omb_completion_resolve_breaks { | ||
if [[ ${cur[1]} ]]; then | ||
local i | ||
for i in "${!COMPREPLY[@]}"; do | ||
if [[ ${COMPREPLY[i]} == "$cur_prefix"* ]]; then | ||
COMPREPLY[i]=${COMPREPLY[i]#"$cur_prefix"} | ||
else | ||
unset -v 'COMPREPLY[i]' | ||
fi | ||
done | ||
COMPREPLY=("${COMPREPLY[@]}") | ||
fi | ||
} |