Fish Shell Completion File

59 views
Skip to first unread message

Dustin Johnson

unread,
Mar 8, 2014, 11:50:12 PM3/8/14
to apt-cyg...@googlegroups.com
Here is some code for fish users which will perform completion. Completion on "install" will list available packages in the current cached .ini and remove is populated via the 'show' command.


#apt-cyg.fish
#completion for apt-cyg

function __fish_apt_cyg_no_subcommand --description 'Test if apt has yet to be given the subcommand'
        for i in (commandline -opc)
                if contains -- $i update install remove find describe show packageof
                        return 1
                end
        end
        return 0
end

function __fish_apt_cyg_use_installed_package --description 'Test if apt command should have installed packages as potential completion'
        for i in (commandline -opc)
                if contains -- $i remove
                        return 0
                end
        end
        return 1
end

function __fish_apt_cyg_use_package --description 'Test if apt command should have packages as potential completion'
        for i in (commandline -opc)
                if contains -- $i install
                        return 0
                end
        end
        return 1
end

function __fish_apt_cyg_print_installed_packages --description 'List installed packages in apt-cyg'
        apt-cyg show
end

function __fish_apt_cyg_print_packages --description 'List packages in apt-cyg'
        # Check for just installable packages, and fix for commented lines in list.
        apt-cyg -u find "." | sed -e '1,/installable packages/d' | sed -e '/#/d'
end

complete -f -c apt-cyg -n '__fish_apt_cyg_use_installed_package' -a '(__fish_apt_cyg_print_installed_packages)' --description 'Package'

complete -f -c apt-cyg -n '__fish_apt_cyg_use_package' -a '(__fish_apt_cyg_print_packages)' --description 'Package'

complete -c apt-cyg -l help --description 'Display help and exit'
complete -f -n '__fish_apt_cyg_no_subcommand' -c apt-cyg -a 'install' --description 'Install one or more packages'
complete -f -n '__fish_apt_cyg_no_subcommand' -c apt-cyg -a 'remove' --description 'Remove one or more packages'
complete -f -n '__fish_apt_cyg_no_subcommand' -c apt-cyg -a 'update' --description 'Update sources'
complete -f -n '__fish_apt_cyg_no_subcommand' -c apt-cyg -a 'show' --description 'Show installed packages'
complete -f -n '__fish_apt_cyg_no_subcommand' -c apt-cyg -a 'find' --description 'Find packages matching pattern'
complete -f -n '__fish_apt_cyg_no_subcommand' -c apt-cyg -a 'describe' --description 'Describe packages matching pattern'
complete -f -n '__fish_apt_cyg_no_subcommand' -c apt-cyg -a 'packageof' --description 'Locate parent packages of command or file'
complete -c apt-cyg -l version --description 'Display version and exit'
complete -c apt-cyg -s m -l mirror -r --description 'Set mirror'
complete -c apt-cyg -s c -l cache -r --description 'Set Cache'
complete -c apt-cyg -s f -l file -r --description 'Read package names from a file'
complete -c apt-cyg -s u -l noupdate -r --description 'Read package names from a file'

apt-cyg.fish
Reply all
Reply to author
Forward
0 new messages