Skip to content
This repository has been archived by the owner on Jul 24, 2022. It is now read-only.

Commit

Permalink
add options to run; pretty print and pass to transmission
Browse files Browse the repository at this point in the history
  • Loading branch information
notwa committed Jun 2, 2013
1 parent 01e84ee commit 264706a
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions run
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
#!/usr/bin/env bash
SRCDIR="$(readlink -f "$(dirname "$0")" )"

# TODO: a way to pass opts to transmission-remote

declare -a actions
while getopts 'aph' opt; do
case $opt in
a) actions+=(addtorrent);;
p) actions+=(prettify);;
?) echo -E "usage: $0 [-ap]" 1>&2;;
esac
done

prettify() {
echo -E "$1"$'\n'"dl:"$'\t'"$2"$'\n'"at:"$'\t'"$(date -d @"$3")"
}

declare -a torrents
addtorrent() {
torrents+=("$2")
}

runactions() {
[ ${#actions} = 0 ] && {
cat
return
}
while IFS=$SEP read -r title torrent time; do
echo -E "$title"$'\n'"dl:"$'\t'"$torrent"$'\n'"at:"$'\t'"$(date -d @"$time")"
for a in "${actions[@]}"; do
"$a" "$title" "$torrent" "$time"
done
done
[ ${#torrents} = 0 ] || transmission-remote -a "${torrents[@]}"
}

. "$SRCDIR/meow.sh"
. config.sh
[ -e times.sh ] && { . times.sh; mv times.sh times.sh.old; }
runall | prettify
runall | runactions
exit ${PIPESTATUS[0]}

0 comments on commit 264706a

Please sign in to comment.