Initial commit, with only sav-quotes script
This commit is contained in:
commit
dd820bf691
10 changed files with 93 additions and 0 deletions
2
.stow-rename
Normal file
2
.stow-rename
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
config => .config
|
||||||
|
local => .local
|
6
config/zsh/functions/_sav-quotes
Normal file
6
config/zsh/functions/_sav-quotes
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#compdef sav-quotes
|
||||||
|
|
||||||
|
_sav-quotes() {
|
||||||
|
local sources="$(sav-quotes --completion)"
|
||||||
|
_arguments "*: :($sources)"
|
||||||
|
}
|
44
local/bin/sav-quotes
Executable file
44
local/bin/sav-quotes
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/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}
|
||||||
|
rm $dest
|
||||||
|
|
||||||
|
for i in {1..5}
|
||||||
|
do
|
||||||
|
$src >> $dest
|
||||||
|
wc -l $dest
|
||||||
|
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
|
4
local/share/sav-quotes/format-bash-quotes.sed
Normal file
4
local/share/sav-quotes/format-bash-quotes.sed
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
s/\#.*/%/
|
||||||
|
1,/Add Quote \/ ModApp \/ Search /d
|
||||||
|
/Home \/ Latest /,$d
|
||||||
|
/^ *$/d;s/^ *//
|
10
local/share/sav-quotes/format-qdb-quotes.sed
Normal file
10
local/share/sav-quotes/format-qdb-quotes.sed
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# first we remove indentation from the start of lines
|
||||||
|
s/^ *//
|
||||||
|
# Convert the quote headers to %
|
||||||
|
1,$ s/^\#.*/%/
|
||||||
|
s/Comment:/\nComment:/
|
||||||
|
s/- \[.*//
|
||||||
|
/\[\s\+\]/d
|
||||||
|
1,/TodayLatestBestTopWorst/d
|
||||||
|
/save page/,$d
|
||||||
|
/^ *$/d
|
6
local/share/sav-quotes/format-xkcdb-quotes.sed
Normal file
6
local/share/sav-quotes/format-xkcdb-quotes.sed
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# first we remove indentation from the start of lines
|
||||||
|
s/^ *//
|
||||||
|
# Convert the quote headers to %
|
||||||
|
1,$ s/^\#[0-9].*/%/
|
||||||
|
# and remove the header
|
||||||
|
/%/,$!d
|
5
local/share/sav-quotes/get-bash-quotes
Executable file
5
local/share/sav-quotes/get-bash-quotes
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
links -dump http://bash.org/\?random1 | sed -f "$dir/format-bash-quotes.sed"
|
||||||
|
exit ${PIPESTATUS[0]}
|
5
local/share/sav-quotes/get-qdb-quotes
Executable file
5
local/share/sav-quotes/get-qdb-quotes
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
links -dump http://www.qdb.us/random | sed -f "$dir/format-qdb-quotes.sed"
|
||||||
|
exit ${PIPESTATUS[0]}
|
6
local/share/sav-quotes/get-whatthecommit-quotes
Executable file
6
local/share/sav-quotes/get-whatthecommit-quotes
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
for i in {1..5}; do
|
||||||
|
curl -s http://whatthecommit.com/index.txt || exit 1
|
||||||
|
echo "%"
|
||||||
|
done
|
5
local/share/sav-quotes/get-xkcdb-quotes
Executable file
5
local/share/sav-quotes/get-xkcdb-quotes
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
|
curl http://www.xkcdb.com/\?random1 | hxnormalize -i 0 -l 99999999999 -x | hxremove br | hxselect -cs '\n%\n' 'span.quote' | hxunent
|
||||||
|
exit ${PIPESTATUS[0]}
|
Loading…
Reference in a new issue