mirror of
https://github.com/notwa/rc
synced 2024-11-14 08:29:03 -08:00
overhaul script sourcing and dependency system
This commit is contained in:
parent
752dc2a605
commit
7ae8c5681d
68 changed files with 115 additions and 88 deletions
|
@ -37,13 +37,14 @@ ADDPATH "$HOME/sh"
|
||||||
|
|
||||||
(
|
(
|
||||||
cd ~/sh \
|
cd ~/sh \
|
||||||
&& printf "%s\n" '#!/usr/bin/env false' '[ "${SOURCING:-0}" -gt 0 ] || exit 1' '' \
|
&& printf "%s\n" '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' \
|
||||||
| cat - $(grep -lF 'YES_BASH' $(find ~/sh -maxdepth 1 -type f)) \
|
| cat - $(grep -lF 'YES_BASH' $(find ~/sh -maxdepth 1 -type f)) \
|
||||||
> ~/.sh-bash
|
> ~/.sh-bash
|
||||||
)
|
)
|
||||||
|
|
||||||
: $((SOURCING+=1))
|
dummy() { :; } ### @- return 0, ignoring arguments.
|
||||||
|
preload=dummy
|
||||||
. ~/.sh-bash
|
. ~/.sh-bash
|
||||||
: $((SOURCING-=1))
|
unset preload
|
||||||
|
|
||||||
alias reload='cd; exec bash' ### @- **TODO:** respect initctl like in `.zshrc`.
|
alias reload='cd; exec bash' ### @- **TODO:** respect initctl like in `.zshrc`.
|
||||||
|
|
|
@ -51,7 +51,7 @@ function {
|
||||||
|
|
||||||
[ -s ~/.sh.sha1 ] && read -r b _ < ~/.sh.sha1
|
[ -s ~/.sh.sha1 ] && read -r b _ < ~/.sh.sha1
|
||||||
( cd ~/sh \
|
( cd ~/sh \
|
||||||
&& print -l '#!/usr/bin/env false' '[ "${SOURCING:-0}" -gt 0 ] || exit 1' '' \
|
&& print -l '#!/usr/bin/env false' '[ -n "$preload" ] || exit 1' '' \
|
||||||
| cat - $(grep -lF 'YES_ZSH' *(.)) \
|
| cat - $(grep -lF 'YES_ZSH' *(.)) \
|
||||||
| tee ~/.sh \
|
| tee ~/.sh \
|
||||||
) | sha1sum - \
|
) | sha1sum - \
|
||||||
|
@ -61,9 +61,10 @@ function {
|
||||||
[ "$a" = "$b" ] && touch ~/.sh.zwc || zrecompile -p ~/.sh
|
[ "$a" = "$b" ] && touch ~/.sh.zwc || zrecompile -p ~/.sh
|
||||||
}
|
}
|
||||||
|
|
||||||
: $((SOURCING+=1))
|
dummy() { :; } ### @- return 0, ignoring arguments.
|
||||||
|
preload=dummy
|
||||||
. ~/.sh
|
. ~/.sh
|
||||||
: $((SOURCING-=1))
|
unset preload
|
||||||
|
|
||||||
local fuzzy=`has fzy || print`
|
local fuzzy=`has fzy || print`
|
||||||
|
|
||||||
|
|
2
sh/argc
2
sh/argc
|
@ -59,4 +59,4 @@ argc() { ### @- validate the number of arguments in a function.
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || argc "$@"
|
[ -n "${preload+-}" ] || argc "$@"
|
||||||
|
|
2
sh/arith
2
sh/arith
|
@ -20,4 +20,4 @@ arith() { ### @-
|
||||||
printf "%s\n" "$(($@))"
|
printf "%s\n" "$(($@))"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || arith "$@"
|
[ -n "${preload+-}" ] || arith "$@"
|
||||||
|
|
2
sh/aur
2
sh/aur
|
@ -136,4 +136,4 @@ aur() { ### @-
|
||||||
[ "$fail" -eq 0 ] && return 0 || return 1
|
[ "$fail" -eq 0 ] && return 0 || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || aur "$@"
|
[ -n "${preload+-}" ] || aur "$@"
|
||||||
|
|
|
@ -17,4 +17,4 @@ autosync() { ### @-
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || autosync "$@"
|
[ -n "${preload+-}" ] || autosync "$@"
|
||||||
|
|
2
sh/bak
2
sh/bak
|
@ -30,4 +30,4 @@ bak() { ### @-
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || bak "$@"
|
[ -n "${preload+-}" ] || bak "$@"
|
||||||
|
|
|
@ -19,4 +19,4 @@ baknow() { ### @-
|
||||||
cp -ip "${1:?missing file argument}" "$1.$(now "$1").bak"
|
cp -ip "${1:?missing file argument}" "$1.$(now "$1").bak"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || baknow "$@"
|
[ -n "${preload+-}" ] || baknow "$@"
|
||||||
|
|
8
sh/baks
8
sh/baks
|
@ -4,10 +4,6 @@
|
||||||
# YES_BASH
|
# YES_BASH
|
||||||
# YES_DASH
|
# YES_DASH
|
||||||
|
|
||||||
#: $((SOURCING+=1))
|
|
||||||
#. ~/sh/note # FIXME: don't do this?
|
|
||||||
#: $((SOURCING-=1))
|
|
||||||
|
|
||||||
baks() { ### @-
|
baks() { ### @-
|
||||||
### backup files by copying each and appending *the current* date-time,
|
### backup files by copying each and appending *the current* date-time,
|
||||||
### irrespective of when the files were modified or created.
|
### irrespective of when the files were modified or created.
|
||||||
|
@ -36,4 +32,6 @@ baks() { ### @-
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || baks "$@"
|
preload() { local preload='set -- $@'; while [ $# -gt 0 ]; do . ~/sh/$1 || exit 2; shift; done; }
|
||||||
|
eval ${preload:-preload} note
|
||||||
|
[ -n "${preload+-}" ] || baks "$@"
|
||||||
|
|
2
sh/bin
2
sh/bin
|
@ -20,4 +20,4 @@ bin() { ### @-
|
||||||
printf "%08X\n" "$a"
|
printf "%08X\n" "$a"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || bin "$@"
|
[ -n "${preload+-}" ] || bin "$@"
|
||||||
|
|
|
@ -17,4 +17,4 @@ cdbusiest() { ### @-
|
||||||
cd $d
|
cd $d
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || cdbusiest "$@"
|
[ -n "${preload+-}" ] || cdbusiest "$@"
|
||||||
|
|
|
@ -13,4 +13,4 @@ colors() { ### @-
|
||||||
printf "\e[%dm$(printf " \e[%dm mV \e[40m" {4,10}{0..7})\e[0m\n" {3,9}{0..7}
|
printf "\e[%dm$(printf " \e[%dm mV \e[40m" {4,10}{0..7})\e[0m\n" {3,9}{0..7}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || colors "$@"
|
[ -n "${preload+-}" ] || colors "$@"
|
||||||
|
|
|
@ -22,4 +22,4 @@ compandy() { ### @-
|
||||||
$atk $atk $rel $rel $thresh $thresh $end $knee $gain $start $delay
|
$atk $atk $rel $rel $thresh $thresh $end $knee $gain $start $delay
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || compandy "$@"
|
[ -n "${preload+-}" ] || compandy "$@"
|
||||||
|
|
|
@ -359,4 +359,4 @@ compile() { ### @-
|
||||||
$compiler $std ${final_flags[@]} $file ${libraries[@]} ${warnings[@]} $outflag $out
|
$compiler $std ${final_flags[@]} $file ${libraries[@]} ${warnings[@]} $outflag $out
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || compile "$@"
|
[ -n "${preload+-}" ] || compile "$@"
|
||||||
|
|
|
@ -45,4 +45,4 @@ else
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || confirm "$@"
|
[ -n "${preload+-}" ] || confirm "$@"
|
||||||
|
|
|
@ -19,4 +19,4 @@ countdiff() { ### @-
|
||||||
| awk '/changed/{print $4+$6;a=1}END{if(!a)print 0}'
|
| awk '/changed/{print $4+$6;a=1}END{if(!a)print 0}'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || countdiff "$@"
|
[ -n "${preload+-}" ] || countdiff "$@"
|
||||||
|
|
2
sh/cutv
2
sh/cutv
|
@ -27,4 +27,4 @@ cutv() { ### @-
|
||||||
# -maxrate 9600k -bufsize 12000k -vcodec libx264 -preset medium -crf 22 -vf scale=1280:720
|
# -maxrate 9600k -bufsize 12000k -vcodec libx264 -preset medium -crf 22 -vf scale=1280:720
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || cutv "$@"
|
[ -n "${preload+-}" ] || cutv "$@"
|
||||||
|
|
2
sh/days
2
sh/days
|
@ -14,4 +14,4 @@ days() { ### @-
|
||||||
echo $(( ($(date +%s) - $(date -d "$1" +%s)) / 60 / 60 / 24 ))
|
echo $(( ($(date +%s) - $(date -d "$1" +%s)) / 60 / 60 / 24 ))
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || days "$@"
|
[ -n "${preload+-}" ] || days "$@"
|
||||||
|
|
|
@ -24,4 +24,4 @@ dbusiest() { ### @-
|
||||||
[ -z $d ] && return 1
|
[ -z $d ] && return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || dbusiest
|
[ -n "${preload+-}" ] || dbusiest "$@"
|
||||||
|
|
2
sh/dfu
2
sh/dfu
|
@ -19,4 +19,4 @@ dfu() { ### @-
|
||||||
NR>1{printf"%-20s %7.2f %7.2f %7.2f %7.2f\n",$6,$3/2^20,($3+$4)/2^20,($4)/2^20,($2-$4-$3)/2^20}'
|
NR>1{printf"%-20s %7.2f %7.2f %7.2f %7.2f\n",$6,$3/2^20,($3+$4)/2^20,($4)/2^20,($2-$4-$3)/2^20}'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || dfu
|
[ -n "${preload+-}" ] || dfu "$@"
|
||||||
|
|
4
sh/disf
4
sh/disf
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
# TODO: actually test that this works with dash.
|
# TODO: actually test that this works with dash.
|
||||||
|
|
||||||
function disf() { ### @-
|
disf() { ### @-
|
||||||
### disassemble a single function from an unstripped executable, unreliably.
|
### disassemble a single function from an unstripped executable, unreliably.
|
||||||
[ $# -le 2 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
[ $# -le 2 ] || { printf "%s\n" "$0: too many arguments" >&2; return 1; }
|
||||||
local exe="${1:?first argument should be an unstripped executable}"
|
local exe="${1:?first argument should be an unstripped executable}"
|
||||||
|
@ -15,4 +15,4 @@ function disf() { ### @-
|
||||||
objdump -d -C --no-show-raw-insn "$exe" | sed '/<'"$symbol"'>:/,/^$/!d;//d'
|
objdump -d -C --no-show-raw-insn "$exe" | sed '/<'"$symbol"'>:/,/^$/!d;//d'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || disf "$@"
|
[ -n "${preload+-}" ] || disf "$@"
|
||||||
|
|
|
@ -164,4 +164,4 @@ document() { ### @-
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || document "$@"
|
[ -n "${preload+-}" ] || document "$@"
|
||||||
|
|
2
sh/e
2
sh/e
|
@ -61,4 +61,4 @@ e() { ### @-
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || e "$@"
|
[ -n "${preload+-}" ] || e "$@"
|
||||||
|
|
2
sh/ea
2
sh/ea
|
@ -46,4 +46,4 @@ ea() { ### @- **TODO:** document.
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || ea "$@"
|
[ -n "${preload+-}" ] || ea "$@"
|
||||||
|
|
2
sh/echo2
2
sh/echo2
|
@ -17,4 +17,4 @@ echo2() { ### @-
|
||||||
printf "%s\n" "$*" >&2
|
printf "%s\n" "$*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || echo2 "$@"
|
[ -n "${preload+-}" ] || echo2 "$@"
|
||||||
|
|
|
@ -9,4 +9,4 @@ explore() { ### @- open a single directory in `explorer.exe`, defaulting to `$PW
|
||||||
explorer "$(cygpath -w "${1:-.}")"
|
explorer "$(cygpath -w "${1:-.}")"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || explore "$@"
|
[ -n "${preload+-}" ] || explore "$@"
|
||||||
|
|
2
sh/ff
2
sh/ff
|
@ -10,4 +10,4 @@ ff() { ### @-
|
||||||
find "${1:-.}" -type f | fzy
|
find "${1:-.}" -type f | fzy
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || ff "$@"
|
[ -n "${preload+-}" ] || ff "$@"
|
||||||
|
|
2
sh/ghmd
2
sh/ghmd
|
@ -28,4 +28,4 @@ ghmd() { ### @-
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || ghmd "$@"
|
[ -n "${preload+-}" ] || ghmd "$@"
|
||||||
|
|
2
sh/has
2
sh/has
|
@ -16,4 +16,4 @@ has() { ### @-
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || has "$@"
|
[ -n "${preload+-}" ] || has "$@"
|
||||||
|
|
2
sh/hex
2
sh/hex
|
@ -21,4 +21,4 @@ hex() { ### @-
|
||||||
printf "%08X\n" "$(($@))"
|
printf "%08X\n" "$(($@))"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || hex "$@"
|
[ -n "${preload+-}" ] || hex "$@"
|
||||||
|
|
2
sh/ify
2
sh/ify
|
@ -19,4 +19,4 @@ ify() { ### @-
|
||||||
"$@" | "$ex"
|
"$@" | "$ex"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || ify "$@"
|
[ -n "${preload+-}" ] || ify "$@"
|
||||||
|
|
|
@ -13,4 +13,4 @@ is_empty() { ### @-
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || is_empty "$@"
|
[ -n "${preload+-}" ] || is_empty "$@"
|
||||||
|
|
2
sh/isup
2
sh/isup
|
@ -16,4 +16,4 @@ isup() { ### @-
|
||||||
[ -z "${c#2[0-9][0-9]}" ]
|
[ -z "${c#2[0-9][0-9]}" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || isup "$@"
|
[ -n "${preload+-}" ] || isup "$@"
|
||||||
|
|
|
@ -136,4 +136,4 @@ maybesudo_() { ### @-
|
||||||
# don't put any code here or you'll clobber $?.
|
# don't put any code here or you'll clobber $?.
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || maybesudo_ "$@"
|
[ -n "${preload+-}" ] || maybesudo_ "$@"
|
||||||
|
|
|
@ -40,4 +40,4 @@ minutemaid() { ### @-
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || minutemaid "$@"
|
[ -n "${preload+-}" ] || minutemaid "$@"
|
||||||
|
|
|
@ -47,4 +47,4 @@ monitor() { ### @-
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || monitor "$@"
|
[ -n "${preload+-}" ] || monitor "$@"
|
||||||
|
|
|
@ -53,4 +53,4 @@ EOF
|
||||||
perl ~/opt/local/bin/noccom "$@"
|
perl ~/opt/local/bin/noccom "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || noccom "$@"
|
[ -n "${preload+-}" ] || noccom "$@"
|
||||||
|
|
2
sh/note
2
sh/note
|
@ -12,4 +12,4 @@ note() { ### @-
|
||||||
printf "\033[1m%s\033[0m\n" "$*" >&2
|
printf "\033[1m%s\033[0m\n" "$*" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || note "$@"
|
[ -n "${preload+-}" ] || note "$@"
|
||||||
|
|
2
sh/now
2
sh/now
|
@ -53,4 +53,4 @@ now() { ### @-
|
||||||
echo "${F}_${ms}"
|
echo "${F}_${ms}"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || now "$@"
|
[ -n "${preload+-}" ] || now "$@"
|
||||||
|
|
2
sh/pacbm
2
sh/pacbm
|
@ -18,4 +18,4 @@ pacbm() { ### @-
|
||||||
' | sort -n
|
' | sort -n
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || pacbm "$@"
|
[ -n "${preload+-}" ] || pacbm "$@"
|
||||||
|
|
2
sh/pause
2
sh/pause
|
@ -17,4 +17,4 @@ pause() { ### @-
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || pause "$@"
|
[ -n "${preload+-}" ] || pause "$@"
|
||||||
|
|
2
sh/pegg
2
sh/pegg
|
@ -19,4 +19,4 @@ pegg() { ### @-
|
||||||
pippy "https://github.com/$1/$2/tarball/${3:-master}#egg=$2"
|
pippy "https://github.com/$1/$2/tarball/${3:-master}#egg=$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || pegg "$@"
|
[ -n "${preload+-}" ] || pegg "$@"
|
||||||
|
|
2
sh/pippy
2
sh/pippy
|
@ -12,4 +12,4 @@ pippy() { ### @-
|
||||||
"$sudo" py -m pip install --upgrade --upgrade-strategy only-if-needed "$@"
|
"$sudo" py -m pip install --upgrade --upgrade-strategy only-if-needed "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || pippy "$@"
|
[ -n "${preload+-}" ] || pippy "$@"
|
||||||
|
|
2
sh/pre
2
sh/pre
|
@ -26,4 +26,4 @@ pre() { ### @-
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || pre "$@"
|
[ -n "${preload+-}" ] || pre "$@"
|
||||||
|
|
32
sh/preload
Normal file
32
sh/preload
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/usr/bin/env false
|
||||||
|
# NO_ZSH
|
||||||
|
# NO_BASH
|
||||||
|
# NO_DASH
|
||||||
|
# NO_ASH
|
||||||
|
# NOTE: this is actually compatible with all of the above shells;
|
||||||
|
# i just really don't want it being sourced by accident.
|
||||||
|
# this file really only exists for documentation purposes.
|
||||||
|
|
||||||
|
preload() { ### @- handle dependencies within the [`~/sh/`](/sh) directory.
|
||||||
|
### this function contains more comments than code, so you should read it.
|
||||||
|
# all sourced files from within the preload function will instead
|
||||||
|
# append to the list of files to preload (i.e. dependencies).
|
||||||
|
# dash and ash have no arrays besides $@, so we must use it.
|
||||||
|
local preload='set -- $@'
|
||||||
|
# we want to iterate over $@ like a queue; pushing and popping.
|
||||||
|
# `for` would create a local copy and leave $@ unmodified, so it's no good.
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
# NOTE: there's no quotes here since the surrounding method uses eval,
|
||||||
|
# so paths-with-spaces is already doomed from the start.
|
||||||
|
# however, $HOME can still safely contain spaces.
|
||||||
|
# NOTE: it's important to use an absolute path here.
|
||||||
|
. ~/sh/$1 # yes, you can source files from within functions,
|
||||||
|
# and they even respect your locals.
|
||||||
|
[ $? -eq 0 ] \
|
||||||
|
|| exit 2 # this `exit 2` is just for zsh and bash;
|
||||||
|
# dash and ash do it automatically.
|
||||||
|
# zsh actually uses some other return value,
|
||||||
|
# but we use 2 anyway since everything else uses 2.
|
||||||
|
shift # pop the queue
|
||||||
|
done
|
||||||
|
}
|
2
sh/psbm
2
sh/psbm
|
@ -18,4 +18,4 @@ psbm() { ### @-
|
||||||
' | sort -n
|
' | sort -n
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || psbm "$@"
|
[ -n "${preload+-}" ] || psbm "$@"
|
||||||
|
|
|
@ -13,4 +13,4 @@ randir() { ### @-
|
||||||
find -maxdepth 1 -type d \( -path '/root' -prune -o -print \) | tail -n+2 | shuf | head -n1
|
find -maxdepth 1 -type d \( -path '/root' -prune -o -print \) | tail -n+2 | shuf | head -n1
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || randir "$@"
|
[ -n "${preload+-}" ] || randir "$@"
|
||||||
|
|
|
@ -7,4 +7,4 @@ refresh() { ### @- invoke `hash -r`.
|
||||||
hash -r
|
hash -r
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || refresh "$@"
|
[ -n "${preload+-}" ] || refresh "$@"
|
||||||
|
|
2
sh/rot13
2
sh/rot13
|
@ -16,4 +16,4 @@ rot13() { ### @-
|
||||||
tr -- A-Za-z0-9 N-ZA-Mn-za-m5-90-4
|
tr -- A-Za-z0-9 N-ZA-Mn-za-m5-90-4
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || rot13 "$@"
|
[ -n "${preload+-}" ] || rot13 "$@"
|
||||||
|
|
2
sh/rs
2
sh/rs
|
@ -72,4 +72,4 @@ rs() { ### @-
|
||||||
$o_overwrite "$extless.enc.$ext"
|
$o_overwrite "$extless.enc.$ext"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || rs "$@"
|
[ -n "${preload+-}" ] || rs "$@"
|
||||||
|
|
8
sh/sc
8
sh/sc
|
@ -1,9 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
: $((SOURCING+=1))
|
|
||||||
. ~/sh/ea # FIXME: don't do this? somehow?
|
|
||||||
: $((SOURCING-=1))
|
|
||||||
|
|
||||||
sc_shorten() {
|
sc_shorten() {
|
||||||
REPLY="${1:2:2}${1:5:2}${1:8:2}${1:11:12}"
|
REPLY="${1:2:2}${1:5:2}${1:8:2}${1:11:12}"
|
||||||
}
|
}
|
||||||
|
@ -66,4 +62,6 @@ sc() { ### @-
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || sc "$@"
|
preload() { local preload='set -- $@'; while [ $# -gt 0 ]; do . ~/sh/$1 || exit 2; shift; done; }
|
||||||
|
eval ${preload:-preload} ea
|
||||||
|
[ -n "${preload+-}" ] || sc "$@"
|
||||||
|
|
|
@ -18,4 +18,4 @@ scramble() { ### @-
|
||||||
-e 's/@//g'
|
-e 's/@//g'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || scramble "$@"
|
[ -n "${preload+-}" ] || scramble "$@"
|
||||||
|
|
|
@ -17,4 +17,4 @@ screeny() { ### @-
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || screeny "$@"
|
[ -n "${preload+-}" ] || screeny "$@"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# YES_ZSH
|
# YES_ZSH
|
||||||
|
|
||||||
#: $((SOURCING+=1))
|
|
||||||
#. ~/sh/now # FIXME: don't do this?
|
|
||||||
#: $((SOURCING-=1))
|
|
||||||
|
|
||||||
scropt() { ### @-
|
scropt() { ### @-
|
||||||
### run `scrot` through `optipng` and save the result to `~/play/$(now).png`.
|
### run `scrot` through `optipng` and save the result to `~/play/$(now).png`.
|
||||||
###
|
###
|
||||||
|
@ -18,4 +14,6 @@ scropt() { ### @-
|
||||||
[ $? -eq 0 ] && echo "$fn" || return $?
|
[ $? -eq 0 ] && echo "$fn" || return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || scropt "$@"
|
preload() { local preload='set -- $@'; while [ $# -gt 0 ]; do . ~/sh/$1 || exit 2; shift; done; }
|
||||||
|
eval ${preload:-preload} now
|
||||||
|
[ -n "${preload+-}" ] || scropt "$@"
|
||||||
|
|
|
@ -20,4 +20,4 @@ similar() { ### @-
|
||||||
}'
|
}'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || similar "$@"
|
[ -n "${preload+-}" ] || similar "$@"
|
||||||
|
|
2
sh/slit
2
sh/slit
|
@ -12,4 +12,4 @@ slit() { ### @-
|
||||||
#awk "{ print ${(j:,:):-\$${^@}} }"
|
#awk "{ print ${(j:,:):-\$${^@}} }"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || slit "$@"
|
[ -n "${preload+-}" ] || slit "$@"
|
||||||
|
|
2
sh/slitt
2
sh/slitt
|
@ -15,4 +15,4 @@ slitt() { ### @-
|
||||||
#awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print ${(j:,:):-\$${^@}} }"
|
#awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print ${(j:,:):-\$${^@}} }"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || slitt "$@"
|
[ -n "${preload+-}" ] || slitt "$@"
|
||||||
|
|
2
sh/sram
2
sh/sram
|
@ -49,4 +49,4 @@ sram() { ### @-
|
||||||
revend "$out"
|
revend "$out"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || sram "$@"
|
[ -n "${preload+-}" ] || sram "$@"
|
||||||
|
|
9
sh/stfu
9
sh/stfu
|
@ -1,9 +1,6 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
# YES_ZSH
|
# YES_ZSH
|
||||||
|
|
||||||
#. ~/sh/echo2 # FIXME
|
|
||||||
#. ~/sh/note # FIXME
|
|
||||||
|
|
||||||
stfu() { ### @-
|
stfu() { ### @-
|
||||||
### invoke a command, silencing stdout and stderr *unless* the command fails.
|
### invoke a command, silencing stdout and stderr *unless* the command fails.
|
||||||
###
|
###
|
||||||
|
@ -44,8 +41,8 @@ stfu() { ### @-
|
||||||
### WARNING: The system cannot find the file specified.
|
### WARNING: The system cannot find the file specified.
|
||||||
### asses
|
### asses
|
||||||
### ```
|
### ```
|
||||||
|
|
||||||
[ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
|
[ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; }
|
||||||
|
|
||||||
local temp="${TMP:-/tmp}/stfu"
|
local temp="${TMP:-/tmp}/stfu"
|
||||||
|
|
||||||
local time="$(date -u '+%s')"
|
local time="$(date -u '+%s')"
|
||||||
|
@ -77,4 +74,6 @@ stfu() { ### @-
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || stfu "$@"
|
preload() { local preload='set -- $@'; while [ $# -gt 0 ]; do . ~/sh/$1 || exit 2; shift; done; }
|
||||||
|
eval ${preload:-preload} echo2 note
|
||||||
|
[ -n "${preload+-}" ] || stfu "$@"
|
||||||
|
|
2
sh/sum
2
sh/sum
|
@ -20,4 +20,4 @@ sum() { ### @-
|
||||||
echo "$sum"
|
echo "$sum"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || sum "$@"
|
[ -n "${preload+-}" ] || sum "$@"
|
||||||
|
|
2
sh/sv
2
sh/sv
|
@ -36,4 +36,4 @@ sv() { ### @-
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || sv "$@"
|
[ -n "${preload+-}" ] || sv "$@"
|
||||||
|
|
2
sh/tpad
2
sh/tpad
|
@ -11,4 +11,4 @@ tpad() { ### @-
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || tpad "$@"
|
[ -n "${preload+-}" ] || tpad "$@"
|
||||||
|
|
2
sh/trash
2
sh/trash
|
@ -14,4 +14,4 @@ trash() { ### @-
|
||||||
dd status=none if=/dev/random bs=1 count="${1:?missing count argument}"
|
dd status=none if=/dev/random bs=1 count="${1:?missing count argument}"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || trash "$@"
|
[ -n "${preload+-}" ] || trash "$@"
|
||||||
|
|
2
sh/trunc
2
sh/trunc
|
@ -18,4 +18,4 @@ trunc() { ### @-
|
||||||
awk -vL=${1:-$COLUMNS} '{e=length>L?"…":"";print substr($0,0,L-(e?1:0)) e}'
|
awk -vL=${1:-$COLUMNS} '{e=length>L?"…":"";print substr($0,0,L-(e?1:0)) e}'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || trunc "$@"
|
[ -n "${preload+-}" ] || trunc "$@"
|
||||||
|
|
|
@ -14,4 +14,4 @@ unscreen() { ### @-
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || unscreen "$@"
|
[ -n "${preload+-}" ] || unscreen "$@"
|
||||||
|
|
2
sh/wat
2
sh/wat
|
@ -37,4 +37,4 @@ wat() { ### @-
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || wat "$@"
|
[ -n "${preload+-}" ] || wat "$@"
|
||||||
|
|
2
sh/wipe
2
sh/wipe
|
@ -21,4 +21,4 @@ wipe() { ### @-
|
||||||
echo $'\033[0m\n' | tr -d '$'
|
echo $'\033[0m\n' | tr -d '$'
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || wipe "$@"
|
[ -n "${preload+-}" ] || wipe "$@"
|
||||||
|
|
2
sh/xxp
2
sh/xxp
|
@ -20,4 +20,4 @@ xxp() { ### @-
|
||||||
hexdump -e '15 1 "%02X " 1 1 " %02X\n"' -- "$@"
|
hexdump -e '15 1 "%02X " 1 1 " %02X\n"' -- "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "${SOURCING:-0}" -gt 0 ] || xxp "$@"
|
[ -n "${preload+-}" ] || xxp "$@"
|
||||||
|
|
Loading…
Reference in a new issue