. bash 4.2.29 :
_xxx() { COMPREPLY=( foo ); }
complete -F _xxx x
x bar # pressing tab turns this into x foo
, , . , bash .
, , , - , - . , , . COMPREPLY=($(compgen -P "$dir" -W "${results}")) - :
local IFS=$'\n'
COMPREPLY=( $(find "${dir}" -maxdepth 1 -type d -iname "${cur#*/}*" -printf "%P\n") )
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
COMPREPLY=( "${dir}${COMPREPLY[0]}" )
fi
bash:
_up_prefix() {
local dir cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=()
if [[ ${cur} =~ ^[0-9]+/? ]]; then
dir=$( printf "%${cur%%/*}s" );
dir="${dir// /../}"
if [[ ${cur} == */* ]]; then
dir="${dir}${cur#*/}"
fi
COMPREPLY=( "${dir}" "${dir}." )
elif [[ ${cur} != */* ]]; then
COMPREPLY=( $(IFS='/'; compgen -W "${PWD}" "${cur}") )
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
dir="${PWD%${COMPREPLY[0]}/*}${COMPREPLY[0]}/"
COMPREPLY=( "${dir}" "${dir}." )
fi
fi
}
complete -F _up_prefix -o dirnames up
, . , , : , , , . - .
: , , . , , [[ -d $1 ]] cd , . , .