Compare commits

..

No commits in common. "c1b1767b120a72eba63714d3e9b083b4bf6f4ec6" and "b761e7f2af0010622280e7bef72c492407b1c498" have entirely different histories.

3 changed files with 36 additions and 95 deletions

View file

@ -50,12 +50,10 @@ 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. 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.
### `stow` ### `link`
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. 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` ### `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. 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,30 +1,28 @@
#compdef dots #compdef dots
: ${DOTFILES:=~/dotfiles} : ${DOTFILES:=~/dotfiles}
local context state state_descr line
typeset -A opt_args
local repo local repo
local -a commands repos new_repos local -a commands repos new_repos
commands=( commands=(
bootstrap:'set up initial dotfiles on a new system' bootstrap:'set up initial dotfiles on a new system'
clone:'download dotfiles packages over Git' clone:'download dotfiles packages over Git'
fetch:'retrieve updates to your packages' fetch:'retrieve updates to your packages'
stow:'stow downloaded packages into your ~' link:'install 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' pull:'fetch and apply package updates'
status:'check whether your packages have changes' status:'check whether your packages have changes'
) )
if ! _retrieve_cache dots-repositories; then 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')) 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 _store_cache dots-repositories repos
fi fi
for repo in $repos; [[ -d $DOTFILES/$repo ]] || new_repos+=$repo
_dots_subcommands() { for repo in $repos; [[ -d $DOTFILES/$repo ]] || new_repos+=($repo)
_describe -t commands command commands _arguments '1:cmds:->cmds' '*:: :->args'
} case $state in
cmds) _describe -t commands command commands ;;
_dots_subcommand_parameters() { args) case $line[1] in
case $words[1] in
bootstrap) _nothing ;; # no more arguments! bootstrap) _nothing ;; # no more arguments!
clone) clone)
if (( $#new_repos )); then if (( $#new_repos )); then
@ -32,11 +30,6 @@ _dots_subcommand_parameters() {
else else
_message 'all known packages are already installed, you can still enter a git url manually' _message 'all known packages are already installed, you can still enter a git url manually'
fi ;; fi ;;
fetch|*stow|pull|st|status) _values -w package $DOTFILES/*(/:t) ;; fetch|link|pull|st|status) _values -w package $DOTFILES/*(/:t) ;;
esac ;;
esac esac
}
_arguments \
'(-v --verbose)'{-v,--verbose}'[request verbose output from Git and Stow]' \
': :_dots_subcommands' \
'*:: :_dots_subcommand_parameters'

View file

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