2016-10-07 21:18:21 -04:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
list_srcs() {
|
|
|
|
local src
|
|
|
|
for src in $quotesrc_dir/get-*-quotes; do
|
|
|
|
src=${src:t}
|
|
|
|
src=${src#get-}
|
|
|
|
src=${src%-quotes}
|
|
|
|
print $src
|
|
|
|
done
|
|
|
|
}
|
|
|
|
save_from_src() {
|
|
|
|
mkdir -p ${dest:h}
|
2016-10-27 18:55:07 -04:00
|
|
|
rm -f $dest
|
2016-10-07 21:18:21 -04:00
|
|
|
|
|
|
|
for i in {1..5}
|
|
|
|
do
|
|
|
|
$src >> $dest
|
2016-10-27 18:55:07 -04:00
|
|
|
(( i < 5 )) && echo % >> $dest
|
|
|
|
wc -l $dest
|
2016-10-07 21:18:21 -04:00
|
|
|
done
|
|
|
|
strfile $dest
|
|
|
|
}
|
|
|
|
|
|
|
|
quotesrc_dir=${XDG_DATA_HOME:=~/.local/share}/sav-quotes
|
|
|
|
dest=${XDG_CACHE_HOME:=~/.cache}/sav-quotes/quotes
|
|
|
|
src_spec=${1:-bash}
|
|
|
|
|
|
|
|
if [[ $src_spec = --completion ]]; then
|
|
|
|
list_srcs
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
src=$quotesrc_dir/get-${src_spec}-quotes
|
|
|
|
if [[ -x $src ]]; then
|
|
|
|
if ! $src &>/dev/null; then
|
|
|
|
print Could not connect to quotesrc $src_spec >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
save_from_src $src
|
|
|
|
else
|
|
|
|
echo "Invalid quotesrc specified: $src_spec"
|
|
|
|
echo "Valid quotesrcs are:"
|
|
|
|
list_srcs
|
|
|
|
exit 1
|
|
|
|
fi
|