2015-04-09 23:44:14 +02:00
|
|
|
# GNU Guix --- Functional package management for GNU
|
guix package: Add 'install', 'remove', and 'upgrade' aliases.
* guix/scripts/install.scm, guix/scripts/remove.scm,
guix/scripts/upgrade.scm, tests/guix-package-aliases.sh: New files.
* Makefile.am (MODULES, SH_TESTS): Add them.
* po/guix/POTFILES.in: Add them.
* guix/scripts/package.scm (guix-package): Split with...
(guix-package*): ... this. New procedure.
* doc/guix.texi (Invoking guix package): Document them.
(Binary Installation, Application Setup, Package Management)
(Packages with Multiple Outputs, Package Modules)
(X.509 Certificates, Installing Debugging Files): Use 'guix install' in
simple examples.
* etc/completion/bash/guix (_guix_complete): Handle "install", "remove",
and "upgrade".
2019-04-27 18:04:00 +02:00
|
|
|
# Copyright © 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
|
2015-04-09 23:44:14 +02:00
|
|
|
#
|
|
|
|
# This file is part of GNU Guix.
|
|
|
|
#
|
|
|
|
# GNU Guix is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
# your option) any later version.
|
|
|
|
#
|
|
|
|
# GNU Guix is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# Bash completion for Guix commands.
|
|
|
|
|
2015-08-20 19:57:33 +02:00
|
|
|
declare _guix_available_packages
|
|
|
|
|
2016-09-07 17:33:48 +02:00
|
|
|
_guix_complete_subcommand ()
|
|
|
|
{
|
|
|
|
local command="${COMP_WORDS[1]}"
|
|
|
|
local subcommands="$(${COMP_WORDS[0]} $command --help 2> /dev/null \
|
|
|
|
| grep '^ [a-z]' \
|
|
|
|
| sed -e's/^ \+\([a-z-]\+\).*$/\1/g')"
|
2017-02-06 17:08:35 +01:00
|
|
|
COMPREPLY=($(compgen -W "$subcommands" -- "${COMP_WORDS[$COMP_CWORD]}"))
|
2016-09-07 17:33:48 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 23:44:14 +02:00
|
|
|
_guix_complete_available_package ()
|
|
|
|
{
|
|
|
|
local prefix="$1"
|
2015-08-20 19:57:33 +02:00
|
|
|
if [ -z "$_guix_available_packages" ]
|
|
|
|
then
|
|
|
|
# Cache the complete list because it rarely changes and makes
|
|
|
|
# completion much faster.
|
2016-09-07 16:22:25 +02:00
|
|
|
_guix_available_packages="$(${COMP_WORDS[0]} package -A 2> /dev/null \
|
|
|
|
| cut -f1)"
|
2015-08-20 19:57:33 +02:00
|
|
|
fi
|
|
|
|
COMPREPLY=($(compgen -W "$_guix_available_packages" -- "$prefix"))
|
2015-04-09 23:44:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_guix_complete_installed_package ()
|
|
|
|
{
|
2015-08-20 19:57:33 +02:00
|
|
|
# Here we do not cache the list of installed packages because that
|
|
|
|
# may change over time and the list is relatively small anyway.
|
2015-04-09 23:44:14 +02:00
|
|
|
local prefix="$1"
|
2016-09-07 16:22:25 +02:00
|
|
|
local packages="$(${COMP_WORDS[0]} package -I "^$prefix" 2> /dev/null \
|
|
|
|
| cut -f1)"
|
2015-04-09 23:44:14 +02:00
|
|
|
COMPREPLY=($(compgen -W "$packages" -- "$prefix"))
|
|
|
|
}
|
|
|
|
|
|
|
|
_guix_complete_option ()
|
|
|
|
{
|
2016-09-07 17:33:48 +02:00
|
|
|
local subcommand
|
|
|
|
case "${COMP_WORDS[2]}" in
|
|
|
|
-*) subcommand="";;
|
|
|
|
[a-z]*) subcommand="${COMP_WORDS[2]}";;
|
|
|
|
esac
|
|
|
|
local options="$(${COMP_WORDS[0]} ${COMP_WORDS[1]} $subcommand --help 2> /dev/null \
|
2015-05-01 17:39:39 +02:00
|
|
|
| grep '^ \+-' \
|
2016-09-07 16:22:25 +02:00
|
|
|
| sed -e's/^.*--\([a-zA-Z0-9_-]\+\)\(=\?\).*/--\1\2/g')"
|
2015-04-09 23:44:14 +02:00
|
|
|
compopt -o nospace
|
2016-09-07 17:33:48 +02:00
|
|
|
COMPREPLY=($(compgen -W "$options" -- "${COMP_WORDS[${#COMP_WORDS[*]} - 1]}"))
|
2015-04-09 23:44:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_guix_is_command ()
|
|
|
|
{
|
|
|
|
local word
|
|
|
|
local result="false"
|
|
|
|
for word in ${COMP_WORDS[*]}
|
|
|
|
do
|
|
|
|
if [ "$word" = "$1" ]
|
|
|
|
then
|
|
|
|
result=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
$result
|
|
|
|
}
|
|
|
|
|
|
|
|
_guix_is_removing ()
|
|
|
|
{
|
|
|
|
local word
|
|
|
|
local result="false"
|
|
|
|
for word in ${COMP_WORDS[*]}
|
|
|
|
do
|
|
|
|
case "$word" in
|
|
|
|
--remove|--remove=*|-r)
|
|
|
|
result=true
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
$result
|
|
|
|
}
|
|
|
|
|
|
|
|
_guix_is_dash_L ()
|
|
|
|
{
|
|
|
|
[ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-L" ] \
|
|
|
|
|| { case "${COMP_WORDS[$COMP_CWORD]}" in
|
|
|
|
--load-path=*) true;;
|
|
|
|
*) false;;
|
|
|
|
esac }
|
|
|
|
}
|
|
|
|
|
2018-02-17 10:05:26 +01:00
|
|
|
_guix_is_dash_m ()
|
|
|
|
{
|
|
|
|
[ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-m" ] \
|
|
|
|
|| { case "${COMP_WORDS[$COMP_CWORD]}" in
|
|
|
|
--manifest=*) true;;
|
|
|
|
*) false;;
|
|
|
|
esac }
|
|
|
|
}
|
|
|
|
|
2015-04-09 23:44:14 +02:00
|
|
|
_guix_complete_file ()
|
|
|
|
{
|
|
|
|
# Let Readline complete file names.
|
|
|
|
compopt -o default
|
|
|
|
COMPREPLY=()
|
|
|
|
}
|
|
|
|
|
2017-02-06 17:05:34 +01:00
|
|
|
_guix_complete_pid ()
|
|
|
|
{
|
|
|
|
local pids="$(cd /proc; echo [0-9]*)"
|
|
|
|
COMPREPLY=($(compgen -W "$pids" -- "$1"))
|
|
|
|
}
|
|
|
|
|
2015-08-20 19:57:33 +02:00
|
|
|
declare _guix_subcommands
|
|
|
|
|
2015-04-09 23:44:14 +02:00
|
|
|
_guix_complete ()
|
|
|
|
{
|
|
|
|
local word_count=${#COMP_WORDS[*]}
|
|
|
|
local word_at_point="${COMP_WORDS[$COMP_CWORD]}"
|
|
|
|
|
|
|
|
if [ "$COMP_CWORD" -gt 1 ]
|
|
|
|
then
|
|
|
|
case "$word_at_point" in
|
|
|
|
-*)
|
|
|
|
_guix_complete_option "$word_at_point"
|
|
|
|
return
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $COMP_CWORD in
|
|
|
|
1)
|
2015-08-20 19:57:33 +02:00
|
|
|
if [ -z "$_guix_subcommands" ]
|
|
|
|
then
|
|
|
|
# Cache the list of subcommands to speed things up.
|
2016-09-07 16:22:25 +02:00
|
|
|
_guix_subcommands="$(guix --help 2> /dev/null \
|
|
|
|
| grep '^ ' | cut -c 2-)"
|
2015-08-20 19:57:33 +02:00
|
|
|
fi
|
|
|
|
COMPREPLY=($(compgen -W "$_guix_subcommands" -- "$word_at_point"))
|
2015-04-09 23:44:14 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if _guix_is_command "package"
|
|
|
|
then
|
2018-02-17 10:05:26 +01:00
|
|
|
if _guix_is_dash_L || _guix_is_dash_m
|
2015-04-09 23:44:14 +02:00
|
|
|
then
|
|
|
|
_guix_complete_file
|
|
|
|
elif _guix_is_removing
|
|
|
|
then
|
|
|
|
_guix_complete_installed_package "$word_at_point"
|
|
|
|
else
|
|
|
|
_guix_complete_available_package "$word_at_point"
|
|
|
|
fi
|
guix package: Add 'install', 'remove', and 'upgrade' aliases.
* guix/scripts/install.scm, guix/scripts/remove.scm,
guix/scripts/upgrade.scm, tests/guix-package-aliases.sh: New files.
* Makefile.am (MODULES, SH_TESTS): Add them.
* po/guix/POTFILES.in: Add them.
* guix/scripts/package.scm (guix-package): Split with...
(guix-package*): ... this. New procedure.
* doc/guix.texi (Invoking guix package): Document them.
(Binary Installation, Application Setup, Package Management)
(Packages with Multiple Outputs, Package Modules)
(X.509 Certificates, Installing Debugging Files): Use 'guix install' in
simple examples.
* etc/completion/bash/guix (_guix_complete): Handle "install", "remove",
and "upgrade".
2019-04-27 18:04:00 +02:00
|
|
|
elif _guix_is_command "install"
|
|
|
|
then
|
|
|
|
_guix_complete_available_package "$word_at_point"
|
|
|
|
elif _guix_is_command "remove"
|
|
|
|
then
|
|
|
|
_guix_complete_installed_package "$word_at_point"
|
|
|
|
elif _guix_is_command "upgrade"
|
|
|
|
then
|
|
|
|
_guix_complete_installed_package "$word_at_point"
|
2018-06-30 18:49:29 +02:00
|
|
|
elif _guix_is_command "build"
|
|
|
|
then
|
|
|
|
if _guix_is_dash_L
|
|
|
|
then
|
|
|
|
_guix_complete_file
|
2018-11-05 17:01:38 +01:00
|
|
|
else
|
|
|
|
_guix_complete_available_package "$word_at_point"
|
2018-06-30 18:49:29 +02:00
|
|
|
fi
|
2017-08-20 12:57:00 +02:00
|
|
|
elif _guix_is_command "download"
|
|
|
|
then
|
|
|
|
_guix_complete_file
|
2015-04-09 23:44:14 +02:00
|
|
|
elif _guix_is_command "system"
|
|
|
|
then
|
2017-02-06 16:50:07 +01:00
|
|
|
case $COMP_CWORD in
|
|
|
|
2) _guix_complete_subcommand;;
|
|
|
|
*) _guix_complete_file;; # TODO: restrict to *.scm
|
|
|
|
esac
|
2017-02-06 17:05:34 +01:00
|
|
|
elif _guix_is_command "container"
|
|
|
|
then
|
|
|
|
case $COMP_CWORD in
|
|
|
|
2) _guix_complete_subcommand;;
|
|
|
|
3) _guix_complete_pid "$word_at_point";;
|
|
|
|
*) _guix_complete_file;;
|
|
|
|
esac
|
2016-09-07 17:33:48 +02:00
|
|
|
elif _guix_is_command "import"
|
2015-04-09 23:44:14 +02:00
|
|
|
then
|
2016-09-07 17:33:48 +02:00
|
|
|
_guix_complete_subcommand
|
2017-02-06 15:55:08 +01:00
|
|
|
elif _guix_is_command "hash" || _guix_is_command "gc"
|
2015-04-09 23:44:14 +02:00
|
|
|
then
|
2016-09-07 17:33:48 +02:00
|
|
|
_guix_complete_file
|
2018-06-30 18:50:40 +02:00
|
|
|
elif _guix_is_command "weather"
|
|
|
|
then
|
|
|
|
if _guix_is_dash_m
|
|
|
|
then
|
|
|
|
_guix_complete_file
|
|
|
|
fi
|
2015-04-09 23:44:14 +02:00
|
|
|
else
|
|
|
|
_guix_complete_available_package "$word_at_point"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _guix_complete guix
|