Compare commits
7 commits
b761e7f2af
...
c1b1767b12
Author | SHA1 | Date | |
---|---|---|---|
c1b1767b12 | |||
40b97e0c15 | |||
1ef91ce5f2 | |||
136eddf8dd | |||
008e82924e | |||
f0baf4e02b | |||
553fb254f7 |
3 changed files with 95 additions and 36 deletions
|
@ -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.
|
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.
|
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.
|
||||||
|
|
|
@ -1,28 +1,30 @@
|
||||||
#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'
|
||||||
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'
|
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
|
||||||
|
|
||||||
for repo in $repos; [[ -d $DOTFILES/$repo ]] || new_repos+=($repo)
|
_dots_subcommands() {
|
||||||
_arguments '1:cmds:->cmds' '*:: :->args'
|
_describe -t commands command commands
|
||||||
case $state in
|
}
|
||||||
cmds) _describe -t commands command commands ;;
|
|
||||||
args) case $line[1] in
|
_dots_subcommand_parameters() {
|
||||||
|
case $words[1] in
|
||||||
bootstrap) _nothing ;; # no more arguments!
|
bootstrap) _nothing ;; # no more arguments!
|
||||||
clone)
|
clone)
|
||||||
if (( $#new_repos )); then
|
if (( $#new_repos )); then
|
||||||
|
@ -30,6 +32,11 @@ case $state in
|
||||||
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|link|pull|st|status) _values -w package $DOTFILES/*(/:t) ;;
|
fetch|*stow|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'
|
||||||
|
|
|
@ -15,7 +15,15 @@ supported_stow_versions=(
|
||||||
2.3.2-fixbug56727
|
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
|
echo 'Bootstrapping your dotfiles...' >&2
|
||||||
mkdir -p $DOTFILES
|
mkdir -p $DOTFILES
|
||||||
touch $DOTFILES/.stow
|
touch $DOTFILES/.stow
|
||||||
|
@ -34,8 +42,8 @@ bootstrap() {
|
||||||
install-custom-gnu-stow || return $?
|
install-custom-gnu-stow || return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
clone dots git vim zsh || return $?
|
do-clone dots git vim zsh || return $?
|
||||||
link
|
do-stow
|
||||||
}
|
}
|
||||||
|
|
||||||
install-custom-gnu-stow() {
|
install-custom-gnu-stow() {
|
||||||
|
@ -43,7 +51,7 @@ install-custom-gnu-stow() {
|
||||||
STOW=$DOTFILES/stow/dot-local/bin/stow
|
STOW=$DOTFILES/stow/dot-local/bin/stow
|
||||||
}
|
}
|
||||||
|
|
||||||
clone() {
|
do-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 $?
|
||||||
|
@ -62,10 +70,10 @@ clone-one() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
echo "Retrieving $package from $url now..." >&2
|
echo "Retrieving $package from $url now..." >&2
|
||||||
git clone $url $DOTFILES/$package
|
call-git clone $url $DOTFILES/$package
|
||||||
}
|
}
|
||||||
|
|
||||||
link() {
|
do-stow() {
|
||||||
local -a packages
|
local -a packages
|
||||||
packages=($argv)
|
packages=($argv)
|
||||||
if (( $#packages == 0 )); then
|
if (( $#packages == 0 )); then
|
||||||
|
@ -74,14 +82,48 @@ link() {
|
||||||
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 "Linking all packages ($packages) into $HOME now..." >&2
|
echo "Stowing all packages ($packages) into $HOME now..." >&2
|
||||||
else
|
else
|
||||||
echo "Linking $packages into $HOME now..." >&2
|
echo "Stowing $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
|
||||||
|
}
|
||||||
|
|
||||||
$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() {
|
process-stow-no-folding() {
|
||||||
|
@ -94,28 +136,28 @@ process-stow-no-folding() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch() {
|
do-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
|
||||||
git fetch -p || return $?
|
call-git fetch -p || return $?
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
pull() {
|
do-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
|
||||||
git pull || return $?
|
call-git pull || return $?
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status() {
|
do-status() {
|
||||||
local -a packages
|
local -a packages
|
||||||
packages=($argv)
|
packages=($argv)
|
||||||
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
|
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
|
||||||
|
@ -126,7 +168,7 @@ 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="$(git status --porcelain --ignore-submodules -unormal 2>/dev/null)"
|
git_status="$(call-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
|
||||||
|
@ -159,6 +201,12 @@ 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
|
||||||
|
@ -169,12 +217,14 @@ main() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $comm in
|
case $comm in
|
||||||
bootstrap) bootstrap ;;
|
bootstrap) do-bootstrap ;;
|
||||||
clone) clone ${argv[2,-1]} ;;
|
clone) do-clone ${argv[2,-1]} ;;
|
||||||
fetch) fetch ${argv[2,-1]} ;;
|
fetch) do-fetch ${argv[2,-1]} ;;
|
||||||
link) link ${argv[2,-1]} ;;
|
stow) do-stow ${argv[2,-1]} ;;
|
||||||
pull) pull ${argv[2,-1]} ;;
|
unstow) do-unstow ${argv[2,-1]} ;;
|
||||||
st|status) status ${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 ;;
|
*) echo "Unknown subcommand $comm" >&2; return 2 ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue