Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eopkg completion support #4600

Merged
merged 7 commits into from Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
122 changes: 122 additions & 0 deletions share/completions/eopkg.fish
@@ -0,0 +1,122 @@
#
# Completions for the eopkg command
#

# Frequently used eopkg commands

# Eopkg subcommand
function __fish_eopkg_subcommand -a subcommand
set -e argv[1]
complete -f -c eopkg -n '__fish_use_subcommand' -a $subcommand $argv
end

function __fish_eopkg_subcommand_with_shortcut -a subcommand shortcut
set -e argv[1..2]
complete -f -c eopkg -n '__fish_use_subcommand' -a $subcommand $argv
complete -f -c eopkg -n '__fish_use_subcommand' -a $shortcut $argv
end

# Eopkg subcommand's option
function __fish_eopkg_option
set subcommand $argv[1]
set -e argv[1]
complete -f -c eopkg -n "__fish_seen_subcommand_from $subcommand" $argv
end

function __fish_eopkg_option_with_shortcut
set subcommand $argv[1]
set -e argv[1]
set shortcut $argv[1]
set -e argv[1]
complete -f -c eopkg -n "__fish_seen_subcommand_from $subcommand" $argv
complete -f -c eopkg -n "__fish_seen_subcommand_from $shortcut" $argv
end

# Print additional completion
function __fish_eopkg_print_components -d "Print list of components"
eopkg list-components -N | string replace -r ' .*' ''
end

function __fish_eopkg_print_repos -d "Print list of repositories"
eopkg list-repo -N | string match -e active | string replace -r ' .*' ''
end

# Setup additional completion
complete -f -c eopkg -n '__fish_seen_subcommand_from upgrade up remove rm install it info check' -s c -l component -a "(__fish_eopkg_print_components)" -d "Component"
complete -f -c eopkg -n '__fish_seen_subcommand_from upgrade up remove rm install it info check' -a "(__fish_print_packages)" -d "Package"
complete -f -c eopkg -n '__fish_seen_subcommand_from remove-repo rr enable-repo er disable-repo dr' -a "(__fish_eopkg_print_repos)" -d "Repository"

# Setup eopkg subcommand with shortcut
__fish_eopkg_subcommand_with_shortcut upgrade up -d "Upgrades packages"
__fish_eopkg_option_with_shortcut upgrade up -l security-only -d "Security related upgrades only"
__fish_eopkg_option_with_shortcut upgrade up -s n -l dry-run -d "Show what would be done"
__fish_eopkg_option_with_shortcut upgrade up -s c -l component -f -d "Upgrade component's and recursive components' packages"

__fish_eopkg_subcommand_with_shortcut install it -d "Install packages"
__fish_eopkg_option_with_shortcut install it -l reinstall -d "Reinstall already installed packages"
__fish_eopkg_option_with_shortcut install it -s n -l dry-run -d "Show what would be done"
__fish_eopkg_option_with_shortcut install it -s c -l component -f -d "Install component's and recursive components' packages"

__fish_eopkg_subcommand_with_shortcut remove rm -d "Remove packages"
__fish_eopkg_option_with_shortcut remove rm -l purge -d "Removes everything including changed config files of the package"
__fish_eopkg_option_with_shortcut remove rm -s n -l dry-run -d "Show what would be done"
__fish_eopkg_option_with_shortcut remove rm -s c -l component -f -d "Remove component's and recursive components' packages"

__fish_eopkg_subcommand_with_shortcut remove-orphans rmo -d "Remove orphaned packages"
__fish_eopkg_option_with_shortcut remove-orphans rmo -l purge -d "Remove everything including changed config files of the package"
__fish_eopkg_option_with_shortcut remove-orphans rmo -s n -l dry-run -d "Show what would be done"

__fish_eopkg_subcommand_with_shortcut autoremove rmf -d "Remove packages and dependencies"
__fish_eopkg_option_with_shortcut autoremove rmf -l purge -d "Remove everything including changed config files of the package"
__fish_eopkg_option_with_shortcut autoremove rmf -s n -l dry-run -d "Show what would be done"

__fish_eopkg_subcommand_with_shortcut history hs -d "History of operations"
__fish_eopkg_option_with_shortcut history hs -s l -l last -x -d "Output only the last n operations"
__fish_eopkg_option_with_shortcut history hs -s t -l takeback -x -d "Takeback to the state after the given operation"

__fish_eopkg_subcommand_with_shortcut search sr -d "Search packages"
__fish_eopkg_option_with_shortcut search sr -s r -l repository -x -d "Name of the source or package repository"
__fish_eopkg_option_with_shortcut search sr -l name -d "Search in package name"
__fish_eopkg_option_with_shortcut search sr -l summary -d "Search in package name"
__fish_eopkg_option_with_shortcut search sr -l description -d "Search in package name"

__fish_eopkg_subcommand_with_shortcut search-file sf -d "Search for a file in installed packages"
__fish_eopkg_option_with_shortcut search-file sf -s l -l long -d "Show in long format"
__fish_eopkg_option_with_shortcut search-file sf -s q -l quiet -d "Show only package name"

__fish_eopkg_subcommand_with_shortcut add-repo ar -r -d "Add a repository"
__fish_eopkg_subcommand_with_shortcut remove-repo rr -x -d "Remove repositories"
__fish_eopkg_subcommand_with_shortcut enable-repo er -x -d "Enable repositories"
__fish_eopkg_subcommand_with_shortcut disable-repo dr -x -d "Disable repositories"

__fish_eopkg_subcommand_with_shortcut list-available la -d "List available packages in the repositories"
__fish_eopkg_subcommand_with_shortcut list-components lc -d "List available components"
__fish_eopkg_subcommand_with_shortcut list-installed li -d "List of all installed packages"
__fish_eopkg_subcommand_with_shortcut list-upgrades lu -d "List packages to be upgraded"
__fish_eopkg_subcommand_with_shortcut list-repo lr -d "List repositories"
__fish_eopkg_subcommand_with_shortcut rebuild-db rdb -d "Rebuild the eopkg database"

# Setup eopkg subcommand
__fish_eopkg_subcommand check -d "Verify packages installation"
__fish_eopkg_option check -l config -d "Checks only changed config files of the packages"
__fish_eopkg_option check -s c -l component -x -d "Check installed packages under given component"

__fish_eopkg_subcommand info -d "Display package information"
__fish_eopkg_option info -l xml -d "Output in xml format"
__fish_eopkg_option info -s f -l files -d "Show a list of package files"
__fish_eopkg_option info -s s -l short -d "Do not show details"
__fish_eopkg_option info -s F -l files-path -d "Show only paths"
__fish_eopkg_option info -s c -l component -f -d "Info about given component"

__fish_eopkg_subcommand help -d "Prints help for given command"

# Setup eopkg general option
complete -c eopkg -s D -l destdir -r -d "Change the system root for eopkg commands"
complete -c eopkg -s L -l bandwidth-limit -r -d "Keep bandwidth usage under specified KB's"
complete -c eopkg -s y -l yes-all -d "Assume yes for all yes/no queries"
complete -c eopkg -s v -l verbose -d "Detailed output"
complete -c eopkg -s d -l debug -d "Show debugging information"
complete -c eopkg -s h -l help -d "Show help message and exit"
complete -c eopkg -l version -d "Show program's version number and exit"
complete -c eopkg -s u -l username -r
complete -c eopkg -s p -l password -r
25 changes: 23 additions & 2 deletions share/functions/__fish_print_packages.fish
Expand Up @@ -37,7 +37,8 @@ function __fish_print_packages
# returning information if another pkg_* tool have a lock.
# Listing /var/db/pkg is a clean alternative.
if type -q -f pkg_add
set -l files /var/db/pkg/*; string replace '/var/db/pkg/' '' -- $files
set -l files /var/db/pkg/*
string replace '/var/db/pkg/' '' -- $files
return
end

Expand Down Expand Up @@ -125,6 +126,27 @@ function __fish_print_packages
return
end

# Eopkg is slow in showing list of available packages

if type -q -f eopkg

# If the cache is less than max_age, we do not recalculate it

set cache_file $XDG_CACHE_HOME/.eopkg-cache.$USER
if test -f $cache_file
cat $cache_file
set age (math (date +%s) - (stat -c '%Y' $cache_file))
set max_age 500
if test $age -lt $max_age
return
end
end

# Remove package version information from output and pipe into cache file
eopkg list-available -N | cut -d ' ' -f 1 >$cache_file &
return
end

# This completes the package name from the portage tree.
# True for installing new packages. Function for printing
# installed on the system packages is in completions/emerge.fish
Expand All @@ -142,4 +164,3 @@ function __fish_print_packages
end

end