2016-10-03 09:42:42 -04:00
|
|
|
#!/usr/bin/env zsh
|
2016-10-03 21:31:49 -04:00
|
|
|
zmodload zsh/mapfile
|
2016-10-03 09:42:42 -04:00
|
|
|
|
|
|
|
bootstrap() {
|
|
|
|
echo 'Bootstrapping your dotfiles...' >&2
|
2016-10-03 17:49:44 -04:00
|
|
|
mkdir -p $DOTFILES
|
|
|
|
touch $DOTFILES/.stow
|
2016-10-03 09:42:42 -04:00
|
|
|
if ! hash stow 2>/dev/null; then
|
|
|
|
echo 'GNU Stow is not installed, fetching it...' >&2
|
2016-10-03 17:49:44 -04:00
|
|
|
clone-one stow || return $?
|
2016-10-03 09:42:42 -04:00
|
|
|
STOW=$DOTFILES/stow/.local/bin/stow
|
|
|
|
fi
|
|
|
|
|
2016-10-03 17:36:25 -04:00
|
|
|
clone dots vim zsh || return $?
|
2016-10-03 09:42:42 -04:00
|
|
|
link
|
|
|
|
}
|
|
|
|
|
|
|
|
clone() {
|
2016-10-03 17:49:44 -04:00
|
|
|
echo "Requested packages: $argv" >&2
|
2016-10-03 09:42:42 -04:00
|
|
|
for package in $argv; do
|
2016-10-03 17:33:22 -04:00
|
|
|
clone-one $package || return $?
|
2016-10-03 09:42:42 -04:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
clone-one() {
|
|
|
|
local url=$1
|
|
|
|
local package=${${url##*/}%.git}
|
|
|
|
# Simple package names are fetched from my GitHub repos.
|
2016-10-03 17:33:22 -04:00
|
|
|
[[ $url != */* ]] && url=$GITHUB_USER/dot-$package
|
2016-10-03 09:42:42 -04:00
|
|
|
# user/repo packages are fetched from that user's repos.
|
|
|
|
[[ $url != *:* ]] && url=https://github.com/$url
|
2016-10-03 17:49:44 -04:00
|
|
|
if [[ -d $DOTFILES/$package ]]; then
|
2016-10-03 09:42:42 -04:00
|
|
|
echo "Looks like you already have $package cloned." >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo "Retrieving $package from $url now..." >&2
|
2016-10-03 17:49:44 -04:00
|
|
|
git clone $url $DOTFILES/$package
|
2016-10-03 09:42:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
link() {
|
|
|
|
local packages=($argv)
|
|
|
|
if (( $#packages == 0 )); then
|
|
|
|
packages=( $DOTFILES/*(N:t) )
|
2016-10-03 17:49:44 -04:00
|
|
|
if (( $#packages == 0 )); then
|
|
|
|
echo "No installed packages! Do you want to clone some first?" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo "Linking all packages ($packages) into $HOME now..." >&2
|
|
|
|
else
|
|
|
|
echo "Linking $packages into $HOME now..." >&2
|
2016-10-03 09:42:42 -04:00
|
|
|
fi
|
2016-10-03 21:31:49 -04:00
|
|
|
|
|
|
|
for nofold in $DOTFILES/${^packages}/.stow-no-fold(N); process-stow-no-fold $nofold
|
|
|
|
|
|
|
|
$STOW -d $DOTFILES -t ~ --ignore '^\.stow-no-fold' $packages
|
|
|
|
}
|
|
|
|
|
|
|
|
process-stow-no-fold() {
|
|
|
|
for file in ${(f)mapfile[$1]}; do
|
|
|
|
file=~/$file
|
|
|
|
[[ -e $file ]] && continue
|
|
|
|
mkdir -p ${file:h}
|
|
|
|
touch $file
|
|
|
|
done
|
2016-10-03 09:42:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
status() {
|
|
|
|
local packages=($argv)
|
|
|
|
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
|
|
|
|
local length=${#${(O@)packages//?/X}[1]}
|
|
|
|
cd $DOTFILES
|
|
|
|
for p in $packages; do
|
|
|
|
pushd $p
|
|
|
|
printf "%${length}s " $p
|
|
|
|
if [[ -z "$(command git status --porcelain --ignore-submodules -unormal)" ]]; then
|
|
|
|
print -P "%F{green}clean%f"
|
|
|
|
else
|
|
|
|
print -P "%F{red}unclean%f"
|
|
|
|
fi
|
|
|
|
popd
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
: ${DOTFILES:=~/dotfiles} ${STOW:=stow} ${GITHUB_USER:=00dani}
|
|
|
|
|
|
|
|
local comm=$1
|
|
|
|
if (( $# == 0 )); then
|
|
|
|
if [[ -d $DOTFILES ]]; then
|
|
|
|
comm=status
|
|
|
|
else
|
|
|
|
comm=bootstrap
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $comm in
|
|
|
|
bootstrap) bootstrap ;;
|
|
|
|
clone) clone ${argv[2,-1]} ;;
|
|
|
|
link) link ${argv[2,-1]} ;;
|
|
|
|
st|status) status ${argv[2,-1]} ;;
|
|
|
|
esac
|