Compare commits
No commits in common. "c1b1767b120a72eba63714d3e9b083b4bf6f4ec6" and "b761e7f2af0010622280e7bef72c492407b1c498" have entirely different histories.
c1b1767b12
...
b761e7f2af
3 changed files with 36 additions and 95 deletions
|
@ -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.
|
||||
|
||||
### `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.
|
||||
|
||||
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.
|
||||
|
|
|
@ -1,42 +1,35 @@
|
|||
#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'
|
||||
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)'
|
||||
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
|
||||
|
||||
_dots_subcommands() {
|
||||
_describe -t commands command commands
|
||||
}
|
||||
|
||||
_dots_subcommand_parameters() {
|
||||
case $words[1] in
|
||||
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
|
||||
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|*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'
|
||||
fetch|link|pull|st|status) _values -w package $DOTFILES/*(/:t) ;;
|
||||
esac ;;
|
||||
esac
|
||||
|
|
|
@ -15,15 +15,7 @@ supported_stow_versions=(
|
|||
2.3.2-fixbug56727
|
||||
)
|
||||
|
||||
call-git() {
|
||||
git $argv ${VERBOSE:+-v}
|
||||
}
|
||||
|
||||
call-gnu-stow() {
|
||||
$STOW --dotfiles -d $DOTFILES -t ~ --ignore=${^global_ignore} ${VERBOSE:+-vvv} $argv
|
||||
}
|
||||
|
||||
do-bootstrap() {
|
||||
bootstrap() {
|
||||
echo 'Bootstrapping your dotfiles...' >&2
|
||||
mkdir -p $DOTFILES
|
||||
touch $DOTFILES/.stow
|
||||
|
@ -42,8 +34,8 @@ do-bootstrap() {
|
|||
install-custom-gnu-stow || return $?
|
||||
fi
|
||||
|
||||
do-clone dots git vim zsh || return $?
|
||||
do-stow
|
||||
clone dots git vim zsh || return $?
|
||||
link
|
||||
}
|
||||
|
||||
install-custom-gnu-stow() {
|
||||
|
@ -51,7 +43,7 @@ install-custom-gnu-stow() {
|
|||
STOW=$DOTFILES/stow/dot-local/bin/stow
|
||||
}
|
||||
|
||||
do-clone() {
|
||||
clone() {
|
||||
echo "Requested packages: $argv" >&2
|
||||
for package in $argv; do
|
||||
clone-one $package || return $?
|
||||
|
@ -70,10 +62,10 @@ clone-one() {
|
|||
return 1
|
||||
fi
|
||||
echo "Retrieving $package from $url now..." >&2
|
||||
call-git clone $url $DOTFILES/$package
|
||||
git clone $url $DOTFILES/$package
|
||||
}
|
||||
|
||||
do-stow() {
|
||||
link() {
|
||||
local -a packages
|
||||
packages=($argv)
|
||||
if (( $#packages == 0 )); then
|
||||
|
@ -82,48 +74,14 @@ do-stow() {
|
|||
echo "No installed packages! Do you want to clone some first?" >&2
|
||||
return 1
|
||||
fi
|
||||
echo "Stowing all packages ($packages) into $HOME now..." >&2
|
||||
echo "Linking all packages ($packages) into $HOME now..." >&2
|
||||
else
|
||||
echo "Stowing $packages into $HOME now..." >&2
|
||||
echo "Linking $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
|
||||
}
|
||||
|
||||
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
|
||||
$STOW --dotfiles -d $DOTFILES -t ~ --ignore=${^global_ignore} $packages
|
||||
}
|
||||
|
||||
process-stow-no-folding() {
|
||||
|
@ -136,28 +94,28 @@ process-stow-no-folding() {
|
|||
done
|
||||
}
|
||||
|
||||
do-fetch() {
|
||||
fetch() {
|
||||
local -a packages
|
||||
packages=($argv)
|
||||
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
|
||||
for p in $packages; do
|
||||
cd $DOTFILES/$p
|
||||
call-git fetch -p || return $?
|
||||
git fetch -p || return $?
|
||||
done
|
||||
}
|
||||
|
||||
do-pull() {
|
||||
pull() {
|
||||
local -a packages
|
||||
packages=($argv)
|
||||
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
|
||||
for p in $packages; do
|
||||
cd $DOTFILES/$p
|
||||
call-git pull || return $?
|
||||
git pull || return $?
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
do-status() {
|
||||
status() {
|
||||
local -a packages
|
||||
packages=($argv)
|
||||
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
|
||||
|
@ -168,7 +126,7 @@ do-status() {
|
|||
printf %${length}s' ' $p
|
||||
|
||||
# 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
|
||||
printf '%9s' '' # space across to the last column
|
||||
print -P %F{247}not a git repository%f
|
||||
|
@ -201,12 +159,6 @@ do-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
|
||||
|
@ -217,14 +169,12 @@ main() {
|
|||
fi
|
||||
|
||||
case $comm in
|
||||
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]} ;;
|
||||
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]} ;;
|
||||
*) echo "Unknown subcommand $comm" >&2; return 2 ;;
|
||||
esac
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue