分页: 1 / 1

bash的补全,自定义

发表于 : 2014-02-09 14:52
eexpress

代码: 全选

▶ sed -n '/TAB/,$ p' ~/.bash/alias 
#--------TAB COMPLETION ADD------------------------
#        local cur; COMPREPLY=(); cur=`_get_cword`
_show_installed()
{ COMPREPLY=($(_xfunc dpkg _comp_dpkg_installed_packages `_get_cword`)); return 0; }
_show_all()
{ COMPREPLY=($( apt-cache pkgnames `_get_cword` 2> /dev/null )); return 0; }

_grep_history()
{ COMPREPLY=($(grep '^cd ' ~/.bash_history|sed 's/^cd\s*//'|grep '^[/~]'|grep `_get_cword` 2> /dev/null)); return 0; }
complete -F _grep_history t

complete -F _show_all $default aw ai as
complete -F _show_installed $default ap ar
complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh
t 是补全 cd历史命令的绝对路径。有时候比autojump方便。
aw ai as是aptitude的查询/安装/搜索的别名,补全全部包名。ap ar是aptitude删除的别名,补全已经安装的包名。ssh补全历史记录的主机名。