4-space indentation

This commit is contained in:
Connor Olding 2014-03-15 08:37:34 -07:00
parent 097e116c19
commit 027a8db2e1
3 changed files with 50 additions and 50 deletions

32
run
View File

@ -5,33 +5,33 @@ SRCDIR="$(readlink -f "$(dirname "$0")" )"
declare -a actions declare -a actions
while getopts 'aph' opt; do while getopts 'aph' opt; do
case $opt in case $opt in
a) actions+=(addtorrent);; a) actions+=(addtorrent);;
p) actions+=(prettify);; p) actions+=(prettify);;
?) echo -E "usage: $0 [-ap]" 1>&2;; ?) echo -E "usage: $0 [-ap]" 1>&2;;
esac esac
done done
prettify() { prettify() {
echo -E "$1"$'\n'"dl:"$'\t'"$2"$'\n'"at:"$'\t'"$(date -d @"$3")" echo -E "$1"$'\n'"dl:"$'\t'"$2"$'\n'"at:"$'\t'"$(date -d @"$3")"
} }
declare -a torrents declare -a torrents
addtorrent() { addtorrent() {
torrents+=("$2") torrents+=("$2")
} }
runactions() { runactions() {
[ ${#actions} = 0 ] && { [ ${#actions} = 0 ] && {
cat cat
return return
} }
while IFS=$SEP read -r title torrent time; do while IFS=$SEP read -r title torrent time; do
for a in "${actions[@]}"; do for a in "${actions[@]}"; do
"$a" "$title" "$torrent" "$time" "$a" "$title" "$torrent" "$time"
done
done done
done for t in "${torrents[@]}"; do transmission-remote -a "$t"; done
for t in "${torrents[@]}"; do transmission-remote -a "$t"; done
} }
. "$SRCDIR/meow.sh" . "$SRCDIR/meow.sh"

View File

@ -1,39 +1,39 @@
function opentag(str, tag) { function opentag(str, tag) {
topen="<"tag">" topen="<"tag">"
tclose="</"tag">" tclose="</"tag">"
len=length(tag) len=length(tag)
begin=index(str, topen) begin=index(str, topen)
end=index(str, tclose) end=index(str, tclose)
return (begin && end) ? substr(str, begin+len+2, end-begin-len-2) : "" return (begin && end) ? substr(str, begin+len+2, end-begin-len-2) : ""
} }
function unescape(str) { function unescape(str) {
while (match(str, /&#([0-9]+);/, b)) while (match(str, /&#([0-9]+);/, b))
str=substr(str, 1, RSTART-1) sprintf("%c",b[1]) substr(str, RSTART+RLENGTH) str=substr(str, 1, RSTART-1) sprintf("%c",b[1]) substr(str, RSTART+RLENGTH)
return str return str
} }
function hotdate(str) { function hotdate(str) {
split(str, d, "[ :]") split(str, d, "[ :]")
return mktime(d[4]" "months[d[3]]" "d[2]" "d[5]" "d[6]" "d[7]) return mktime(d[4]" "months[d[3]]" "d[2]" "d[5]" "d[6]" "d[7])
} }
BEGIN{ BEGIN{
# http://stackoverflow.com/a/2123002 # http://stackoverflow.com/a/2123002
m=split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",d,"|") m=split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",d,"|")
for(o=1;o<=m;o++) months[d[o]]=sprintf("%02d",o) for(o=1;o<=m;o++) months[d[o]]=sprintf("%02d",o)
glen=length(g) glen=length(g)
} }
function run(str) { function run(str) {
title=unescape(opentag(str, "title")) title=unescape(opentag(str, "title"))
if (substr(title,1,glen+2) != "["g"]") return if (substr(title,1,glen+2) != "["g"]") return
pub=unescape(opentag($0, "pubDate")) pub=unescape(opentag($0, "pubDate"))
# "date -d \""pub "\" +%s" | getline pubunix # "date -d \""pub "\" +%s" | getline pubunix
pubunix=hotdate(pub) pubunix=hotdate(pub)
if (pubunix <= ts) return if (pubunix <= ts) return
torrent=unescape(opentag(str, "link")) torrent=unescape(opentag(str, "link"))
print title sep torrent sep pubunix print title sep torrent sep pubunix
} }
{run($0)} {run($0)}

View File

@ -1,13 +1,13 @@
{ {
str=$0 str=$0
topen="<"tag">" topen="<"tag">"
tclose="</"tag">" tclose="</"tag">"
len=length(tag) len=length(tag)
for (;;) { for (;;) {
begin=index(str, topen) begin=index(str, topen)
end=index(str,tclose) end=index(str,tclose)
if (!(begin || end)) break if (!(begin || end)) break
print substr(str, begin+len+2, end-begin-len-2) print substr(str, begin+len+2, end-begin-len-2)
str=substr(str, end+len+3) str=substr(str, end+len+3)
} }
} }