dots/config/zsh/functions/_dots
Danielle McLean 8bfca07760
Update _dots to pull list of repos from Gitea
I completely forgot I made the _dots completion function do this in the
first place. Past Dani did some really cool stuff! Anyway, the dot
repos now live on Gitea, so the completion function needs to fetch the
list from there instead. It's not difficult, the API is very simple.
2021-07-15 09:18:45 +10:00

36 lines
1.1 KiB
Plaintext

#compdef dots
: ${DOTFILES:=~/dotfiles}
local context state state_descr line
typeset -A opt_args
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'
link:'install downloaded packages into your ~'
pull:'fetch and apply package updates'
status:'check whether your packages have changes'
)
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'))
_store_cache dots-repositories repos
fi
for repo in $repos; [[ -d $DOTFILES/$repo ]] || new_repos+=($repo)
_arguments '1:cmds:->cmds' '*:: :->args'
case $state in
cmds) _describe -t commands command commands ;;
args) case $line[1] in
bootstrap) _nothing ;; # no more arguments!
clone)
if (( $#new_repos )); then
_values -w package $new_repos
else
_message 'all known packages are already installed, you can still enter a git url manually'
fi ;;
fetch|link|pull|st|status) _values -w package $DOTFILES/*(/:t) ;;
esac ;;
esac