Compare commits

...

7 commits

3 changed files with 95 additions and 36 deletions

View file

@ -50,10 +50,12 @@ Will clone one or more packages specified into your `DOTFILES` directory. Packag
Will simply run `git fetch -p` for each of the specified package names. If there are no package names provided, will implicitly run over *all* packages.
### `link`
### `stow`
Will employ GNU Stow to symlink each of the packages specified by name into your `HOME`. If no package names are provided, will implicitly link all packages.
Additionally, `unstow` and `restow` commands are available with the same interface. These three commands correspond to the `-S`, `-D`, and `-R` modes Stow can be run in.
### `pull`
Very similar to `fetch`. Will simply run `git pull` for each of the specified package names. If there are no package names provided, will implicitly run over *all* packages.

View file

@ -1,35 +1,42 @@
#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 ~'
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'
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
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
_dots_subcommands() {
_describe -t commands command commands
}
_dots_subcommand_parameters() {
case $words[1] in
bootstrap) _nothing ;; # no more arguments!
clone)
if (( $#new_repos )); then
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
fetch|*stow|pull|st|status) _values -w package $DOTFILES/*(/:t) ;;
esac
}
_arguments \
'(-v --verbose)'{-v,--verbose}'[request verbose output from Git and Stow]' \
': :_dots_subcommands' \
'*:: :_dots_subcommand_parameters'

View file

@ -15,7 +15,15 @@ supported_stow_versions=(
2.3.2-fixbug56727
)
bootstrap() {
call-git() {
git $argv ${VERBOSE:+-v}
}
call-gnu-stow() {
$STOW --dotfiles -d $DOTFILES -t ~ --ignore=${^global_ignore} ${VERBOSE:+-vvv} $argv
}
do-bootstrap() {
echo 'Bootstrapping your dotfiles...' >&2
mkdir -p $DOTFILES
touch $DOTFILES/.stow
@ -34,8 +42,8 @@ bootstrap() {
install-custom-gnu-stow || return $?
fi
clone dots git vim zsh || return $?
link
do-clone dots git vim zsh || return $?
do-stow
}
install-custom-gnu-stow() {
@ -43,7 +51,7 @@ install-custom-gnu-stow() {
STOW=$DOTFILES/stow/dot-local/bin/stow
}
clone() {
do-clone() {
echo "Requested packages: $argv" >&2
for package in $argv; do
clone-one $package || return $?
@ -62,10 +70,10 @@ clone-one() {
return 1
fi
echo "Retrieving $package from $url now..." >&2
git clone $url $DOTFILES/$package
call-git clone $url $DOTFILES/$package
}
link() {
do-stow() {
local -a packages
packages=($argv)
if (( $#packages == 0 )); then
@ -74,14 +82,48 @@ link() {
echo "No installed packages! Do you want to clone some first?" >&2
return 1
fi
echo "Linking all packages ($packages) into $HOME now..." >&2
echo "Stowing all packages ($packages) into $HOME now..." >&2
else
echo "Linking $packages into $HOME now..." >&2
echo "Stowing $packages into $HOME now..." >&2
fi
for nofold in $DOTFILES/${^packages}/.stow-no-folding(N); process-stow-no-folding $nofold
call-gnu-stow -S $packages
}
$STOW --dotfiles -d $DOTFILES -t ~ --ignore=${^global_ignore} $packages
do-unstow() {
local -a packages
packages=($argv)
if (( $#packages == 0 )); then
packages=( $DOTFILES/*(N:t) )
if (( $#packages == 0 )); then
echo "No installed packages! There's nothing to unstow!" >&2
return 1
fi
echo "Unstowing all packages ($packages) from $HOME now..." >&2
else
echo "Unstowing $packages from $HOME now..." >&2
fi
call-gnu-stow -D $packages
}
do-restow() {
local -a packages
packages=($argv)
if (( $#packages == 0 )); then
packages=( $DOTFILES/*(N:t) )
if (( $#packages == 0 )); then
echo "No installed packages! Do you want to clone some first?" >&2
return 1
fi
echo "Restowing all packages ($packages) into $HOME now..." >&2
else
echo "Restowing $packages into $HOME now..." >&2
fi
for nofold in $DOTFILES/${^packages}/.stow-no-folding(N); process-stow-no-folding $nofold
call-gnu-stow -R $packages
}
process-stow-no-folding() {
@ -94,28 +136,28 @@ process-stow-no-folding() {
done
}
fetch() {
do-fetch() {
local -a packages
packages=($argv)
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
for p in $packages; do
cd $DOTFILES/$p
git fetch -p || return $?
call-git fetch -p || return $?
done
}
pull() {
do-pull() {
local -a packages
packages=($argv)
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
for p in $packages; do
cd $DOTFILES/$p
git pull || return $?
call-git pull || return $?
done
}
status() {
do-status() {
local -a packages
packages=($argv)
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
@ -126,7 +168,7 @@ status() {
printf %${length}s' ' $p
# Check if the package is actually a repo. It might not be if it's brand-new.
git_status="$(git status --porcelain --ignore-submodules -unormal 2>/dev/null)"
git_status="$(call-git status --porcelain --ignore-submodules -unormal 2>/dev/null)"
if (( $? != 0 )); then
printf '%9s' '' # space across to the last column
print -P %F{247}not a git repository%f
@ -159,6 +201,12 @@ status() {
main() {
: ${DOTFILES:=~/dotfiles} ${STOW:=stow} ${DOTS_SOURCE_PREFIX:=https://git.00dani.me/dot}
local opt_index=$argv[(I)(-v|--verbose)]
if (( opt_index != 0 )); then
VERBOSE=yes
argv[opt_index]=()
fi
comm=$1
if (( $# == 0 )); then
if [[ -d $DOTFILES ]]; then
@ -169,12 +217,14 @@ main() {
fi
case $comm in
bootstrap) bootstrap ;;
clone) clone ${argv[2,-1]} ;;
fetch) fetch ${argv[2,-1]} ;;
link) link ${argv[2,-1]} ;;
pull) pull ${argv[2,-1]} ;;
st|status) status ${argv[2,-1]} ;;
bootstrap) do-bootstrap ;;
clone) do-clone ${argv[2,-1]} ;;
fetch) do-fetch ${argv[2,-1]} ;;
stow) do-stow ${argv[2,-1]} ;;
unstow) do-unstow ${argv[2,-1]} ;;
restow) do-restow ${argv[2,-1]} ;;
pull) do-pull ${argv[2,-1]} ;;
st|status) do-status ${argv[2,-1]} ;;
*) echo "Unknown subcommand $comm" >&2; return 2 ;;
esac
}