我按照本教程为figlet
/设置自动完成功能toilet
。
# bash completion for figlet/toilet
have figlet &&
_figlet()
{
local prev cur opts
_get_comp_words_by_ref cur prev
opts="-f"
COMPREPLY=()
case $prev in
-f)
local running=$(find /usr/share/figlet -name '*.flf' -printf '%P\n' | sed 's/\.flf$//')
COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
return 0
;;
*)
;;
esac
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
return 0
} &&
complete -F _figlet figlet
###################################################################################################
have toilet &&
_toilet()
{
local prev cur opts
_get_comp_words_by_ref cur prev
opts="-f"
COMPREPLY=()
case $prev in
-f)
local running=$(find /usr/share/figlet -name '*.[tf]lf' -printf '%P\n' | sed 's/\.[tf]lf$//')
COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
return 0
;;
*)
;;
esac
COMPREPLY=( $( compgen -W "$opts" -- "$cur" ) )
return 0
} &&
complete -F _toilet toilet
_figlet
并且_toilet
几乎相同,除了find
/sed
命令中的模式。
如何提取一个_figlet_toilet
以模式作为参数的函数?