dots/dot-config/zsh/functions/_dots

43 lines
1.3 KiB
Text
Raw Normal View History

2016-10-27 01:33:59 -04:00
#compdef dots
: ${DOTFILES:=~/dotfiles}
local repo
local -a commands repos new_repos
commands=(
bootstrap:'set up initial dotfiles on a new system'
clone:'download dotfiles packages over Git'
fetch:'retrieve updates to your packages'
stow:'stow downloaded packages into your ~'
unstow:'unstow installed packages (cleans up their symlinks)'
restow:'unstow then stow installed packages (may be useful if package layout changed)'
pull:'fetch and apply package updates'
2016-10-27 01:33:59 -04:00
status:'check whether your packages have changes'
)
2023-12-05 05:26:57 -05:00
2016-10-27 01:33:59 -04:00
if ! _retrieve_cache dots-repositories; then
repos=($(curl -s -X GET "https://git.00dani.me/api/v1/orgs/dot/repos" -H "accept: application/json" | jq -r '.[].name'))
2016-10-27 01:33:59 -04:00
_store_cache dots-repositories repos
fi
2023-12-05 05:26:57 -05:00
for repo in $repos; [[ -d $DOTFILES/$repo ]] || new_repos+=$repo
2016-10-27 01:33:59 -04:00
2023-12-05 05:26:57 -05:00
_dots_subcommands() {
_describe -t commands command commands
}
_dots_subcommand_parameters() {
case $words[1] in
2016-10-27 01:33:59 -04:00
bootstrap) _nothing ;; # no more arguments!
2023-12-05 05:26:57 -05:00
clone)
if (( $#new_repos )); then
2016-10-27 01:33:59 -04:00
_values -w package $new_repos
else
_message 'all known packages are already installed, you can still enter a git url manually'
fi ;;
fetch|*stow|pull|st|status) _values -w package $DOTFILES/*(/:t) ;;
2023-12-05 05:26:57 -05:00
esac
}
_arguments \
'(-v --verbose)'{-v,--verbose}'[request verbose output from Git and Stow]' \
': :_dots_subcommands' \
'*:: :_dots_subcommand_parameters'