0

The good method for completion for alias in this web https://ubuntuforums.org/showthread.php?t=733397.

Now in 16.04, seems rules changed.

I can not find apt(_apt) completion command. but ls is(_longopt) here and it can works. of course apt also not in /etc/bash_completion.d/.

▶ complete |grep apt
▶ complete |grep '\<ls\>'
complete -F _longopt ls
▶ complete |grep 'upstart'
complete -F _upstart_reload reload
complete -F _upstart_stop stop
complete -F _upstart_initctl initctl
complete -F _upstart_start start
complete -F _upstart_status status
complete -F _upstart_restart restart
0

OK, I return to other old version, and this works. according to the file /usr/share/bash-completion/completions/apt.

alias ai='sudo apt install'
alias ap='sudo apt purge'
alias au='sudo apt update && msg 列表已经刷新 || msg 刷新失败'
alias ag='sudo apt upgrade'
alias as='apt list'
alias aw='apt show'
alias aa='sudo apt autoremove'

_show_installed()
{
        local cur
        COMPREPLY=()
        cur=`_get_cword`
        COMPREPLY=( $( _xfunc dpkg _comp_dpkg_installed_packages $cur ) )
        return 0
}
_show_all()
{
        local cur
        COMPREPLY=()
        cur=`_get_cword`
        COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
        return 0
}
complete -F _show_all $default aw ai as
complete -F _show_installed $default ap

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.