Simplified approach to curl|zsh safety

This commit is contained in:
Danielle McLean 2023-10-16 13:36:04 +11:00
parent a68231a64f
commit 1ce8a8d95c
Signed by: 00dani
GPG key ID: 52C059C3B22A753E

View file

@ -1,6 +1,7 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
# <a href="https://dots.00dani.me/README">WHAT IS THIS</a> # <a href="https://dots.00dani.me/README">WHAT IS THIS</a>
{ # Wrap the entire program in a braced block so it won't run at all if you do curl | zsh and the connection drops.
global_ignore=( global_ignore=(
'\.git.*' '\.git.*'
'README\.md' 'README\.md'
@ -10,7 +11,7 @@ global_ignore=(
'\..*\.swp' '\..*\.swp'
) )
'bootstrap'() { bootstrap() {
echo 'Bootstrapping your dotfiles...' >&2 echo 'Bootstrapping your dotfiles...' >&2
mkdir -p $DOTFILES mkdir -p $DOTFILES
touch $DOTFILES/.stow touch $DOTFILES/.stow
@ -24,14 +25,14 @@ global_ignore=(
link link
} }
'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 $?
done done
} }
'clone-one'() { clone-one() {
local url=$1 local url=$1
local package=${${url##*/}%.git} local package=${${url##*/}%.git}
# Simple package names are fetched from the configured source prefix. # Simple package names are fetched from the configured source prefix.
@ -46,7 +47,7 @@ global_ignore=(
git clone $url $DOTFILES/$package git clone $url $DOTFILES/$package
} }
'link'() { link() {
local -a packages local -a packages
packages=($argv) packages=($argv)
if (( $#packages == 0 )); then if (( $#packages == 0 )); then
@ -65,7 +66,7 @@ global_ignore=(
$STOW -d $DOTFILES -t ~ --ignore=${^global_ignore} $packages $STOW -d $DOTFILES -t ~ --ignore=${^global_ignore} $packages
} }
'process-stow-no-folding'() { process-stow-no-folding() {
zmodload zsh/mapfile zmodload zsh/mapfile
for file in ${(f)mapfile[$1]}; do for file in ${(f)mapfile[$1]}; do
file=~/$file file=~/$file
@ -75,7 +76,7 @@ global_ignore=(
done done
} }
'fetch'() { fetch() {
local -a packages local -a packages
packages=($argv) packages=($argv)
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) ) (( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
@ -85,7 +86,7 @@ global_ignore=(
done done
} }
'pull'() { pull() {
local -a packages local -a packages
packages=($argv) packages=($argv)
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) ) (( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
@ -96,7 +97,7 @@ global_ignore=(
} }
'status'() { status() {
local -a packages local -a packages
packages=($argv) packages=($argv)
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) ) (( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
@ -137,7 +138,7 @@ global_ignore=(
done done
} }
'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}
comm=$1 comm=$1
@ -159,4 +160,5 @@ global_ignore=(
esac esac
} }
{'main' "$@"} main "$@"
} # Wrap the entire program in a braced block so it won't run at all if you do curl | zsh and the connection drops.