Completion: Update manager completion to the new argument structure
This commit is contained in:
+125
-17
@@ -1,25 +1,133 @@
|
|||||||
#compdef dotfiles.sh
|
#compdef dotfiles.sh
|
||||||
|
|
||||||
_dotfiles.sh() {
|
typeset -A opt_args
|
||||||
integer ret=1
|
|
||||||
|
# Argument definition
|
||||||
|
# ------------------------------------------
|
||||||
|
|
||||||
|
_dotfiles_operations=(
|
||||||
|
{-F-,--file}'[display all files added to the dotfiles directory]'
|
||||||
|
{-P-,--package}'[instal, print or store packages]'
|
||||||
|
'(-)'{-h,--help}'[display usage message and exit]'
|
||||||
|
)
|
||||||
|
|
||||||
|
_dotfiles_file_options=(
|
||||||
|
'(-F --file)'{-F,--file}
|
||||||
|
'(-a --add)'{-a,--add}'[add selected file paths to the dotfiles directory]'
|
||||||
|
'(-l --pull)'{-l,--pull}'[pull file(s) from the system to the dotfiles directory]'
|
||||||
|
'(-s --push)'{-s,--push}'[push file(s) from the dotfiles directory to the system]'
|
||||||
|
)
|
||||||
|
|
||||||
|
_dotfiles_package_options=(
|
||||||
|
'(-P --package)'{-P,--package}
|
||||||
|
'(-a --aur-install)'{-a,--aur-install}'[install all AUR packages of the stored list]'
|
||||||
|
'(-i --install)'{-i,--install}'[install all official packages of the stored list]'
|
||||||
|
'(-s --store)'{-s,--store}'[stores a list of all installed packages on the system]'
|
||||||
|
)
|
||||||
|
|
||||||
|
_dotfiles_dotfile_directory_target=(
|
||||||
|
'*:file:_files'
|
||||||
|
)
|
||||||
|
|
||||||
|
_dotfiles_home_directory_target=(
|
||||||
|
'*:file:_files -W ~/'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Argument handling
|
||||||
|
# ------------------------------------------
|
||||||
|
|
||||||
|
function _dotfiles_file_argument_handling()
|
||||||
|
{
|
||||||
|
case "$tmp" in
|
||||||
|
-*)
|
||||||
|
_arguments -s : "$_dotfiles_file_options[@]" && result=0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# Enable matching of dotfiles without explicitly specifying the dot
|
||||||
|
setopt globdots
|
||||||
|
|
||||||
|
case "$args" in
|
||||||
|
*a*)
|
||||||
|
_arguments -s : "$_dotfiles_home_directory_target[@]" && result=0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_arguments -s : "$_dotfiles_dotfile_directory_target[@]" && result=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
function _dotfiles_package_argument_handling()
|
||||||
|
{
|
||||||
|
case "$tmp" in
|
||||||
|
-*)
|
||||||
|
_arguments -s : "$_dotfiles_package_options[@]" && result=0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
case "$args" in
|
||||||
|
P)
|
||||||
|
_arguments -s : '*:package:_dotfiles_completions_tracked_packages' && result=0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! zmodload -s zsh/mapfile; then
|
||||||
|
function _dotfiles_completions_tracked_packages() {}
|
||||||
|
else
|
||||||
|
function _dotfiles_completions_tracked_packages()
|
||||||
|
{
|
||||||
|
local -a packages
|
||||||
|
packages=( "${(f@)${mapfile[packages]%$'\n'}}" )
|
||||||
|
readonly packages
|
||||||
|
compadd "$@" -a packages
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Completion control flow
|
||||||
|
# ------------------------------------------
|
||||||
|
|
||||||
|
_dotfiles.sh()
|
||||||
|
{
|
||||||
|
local result=1
|
||||||
local -a args
|
local -a args
|
||||||
|
local tmp
|
||||||
|
|
||||||
args+=(
|
# Get all short flags
|
||||||
'*'{-a,--add=}'[add file to the dotfiles directory]:file:_files'
|
args=( ${${${(M)words:#-*}#-}:#-*} )
|
||||||
'(-f --files)'{-f,--files}'[display all files added to the dotfiles directory]'
|
# Get the current flag
|
||||||
'(-)'{-h,--help}'[display usage message and exit]'
|
tmp="$words[-1]"
|
||||||
'(-p --packages)'{-p,--packages=}'[instal, list or store packages]:package functions:((
|
|
||||||
install\:"install all core packages of the stored list"
|
|
||||||
install-aur\:"install all AUR packages of the stored list"
|
|
||||||
list\:"display all packages installed on the system (default)"
|
|
||||||
store\:"stores a list of all installed packages"
|
|
||||||
))'
|
|
||||||
'(-l --pull)'{-l,--pull}'[pull each added file from system to dotfiles directory]'
|
|
||||||
'(-s --push)'{-s,--push}'[push each added file to its location on the system]'
|
|
||||||
)
|
|
||||||
|
|
||||||
_arguments -s -S $args[@] && ret=0
|
case "$args" in
|
||||||
return ret
|
h*)
|
||||||
|
_message -e arguments "no more arguments"
|
||||||
|
;;
|
||||||
|
F*)
|
||||||
|
_dotfiles_file_argument_handling
|
||||||
|
;;
|
||||||
|
P*)
|
||||||
|
_dotfiles_package_argument_handling
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
case ${(M)words:#--*} in
|
||||||
|
*--file*)
|
||||||
|
_dotfiles_file_argument_handling
|
||||||
|
;;
|
||||||
|
*--package*)
|
||||||
|
_dotfiles_package_argument_handling
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_arguments -s : "$_dotfiles_operations[@]" && result=0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
_dotfiles.sh
|
_dotfiles.sh
|
||||||
|
|||||||
Reference in New Issue
Block a user