bash completion: Fix & unify option parsing.

We now correctly recognise ‘guix -Abcdef’ as equivalent to ‘guix -f’.

* etc/completion/bash/guix (_guix_is_short_option, guix_is_long_option):
New functions.
(_guix_is_dash_f, _guix_is_dash_l, _guix_is_dash_L, _guix_is_dash_m)
(_guix_is_dash_C, _guix_is_dash_p): Use them.
This commit is contained in:
Tobias Geerinckx-Rice 2022-05-22 02:00:00 +02:00
parent 4cb6994790
commit dc6d92ac93
No known key found for this signature in database
GPG Key ID: 0DB0FF884F556D79

@ -117,58 +117,59 @@ _guix_is_removing ()
$result $result
} }
_guix_is_short_option ()
{
case "${COMP_WORDS[$COMP_CWORD - 1]}" in
--*) false;;
-*$1) true ;;
*) false ;;
esac
}
_guix_is_long_option ()
{
# Don't handle (non-GNU?) --long-option VALUE, as Guix doesn't either.
case "${COMP_WORDS[$COMP_CWORD]}" in
--$1=*) true ;;
*) false ;;
esac
}
_guix_is_dash_f () _guix_is_dash_f ()
{ {
[ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-f" ] \ _guix_is_short_option f ||
|| { case "${COMP_WORDS[$COMP_CWORD]}" in _guix_is_long_option file ||
--file=*|--install-from-file=*) true;; _guix_is_long_option install-from-file
*) false;;
esac }
} }
_guix_is_dash_l () _guix_is_dash_l ()
{ {
[ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-l" ] \ _guix_is_short_option l ||
|| { case "${COMP_WORDS[$COMP_CWORD]}" in _guix_is_long_option load
--load=*) true;;
*) false;;
esac }
} }
_guix_is_dash_L () _guix_is_dash_L ()
{ {
[ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-L" ] \ _guix_is_short_option L ||
|| { case "${COMP_WORDS[$COMP_CWORD]}" in _guix_is_long_option load-path
--load-path=*) true;;
*) false;;
esac }
} }
_guix_is_dash_m () _guix_is_dash_m ()
{ {
[ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-m" ] \ _guix_is_short_option m ||
|| { case "${COMP_WORDS[$COMP_CWORD]}" in _guix_is_long_option manifest
--manifest=*) true;;
*) false;;
esac }
} }
_guix_is_dash_C () _guix_is_dash_C ()
{ {
[ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-C" ] \ _guix_is_short_option C ||
|| { case "${COMP_WORDS[$COMP_CWORD]}" in _guix_is_long_option channels
--channels=*) true;;
*) false;;
esac }
} }
_guix_is_dash_p () _guix_is_dash_p ()
{ {
[ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-p" ] \ _guix_is_short_option p ||
|| { case "${COMP_WORDS[$COMP_CWORD]}" in _guix_is_long_option profile
--profile=*) true;;
*) false;;
esac }
} }
_guix_complete_file () _guix_complete_file ()