aboutsummaryrefslogtreecommitdiff
path: root/litterbox
diff options
context:
space:
mode:
Diffstat (limited to 'litterbox')
-rwxr-xr-xlitterbox33
1 files changed, 27 insertions, 6 deletions
diff --git a/litterbox b/litterbox
index 7e2f980..c60e35c 100755
--- a/litterbox
+++ b/litterbox
@@ -45,6 +45,11 @@ pluralize() {
[ "$1" != 1 ] && echo -n "s"
}
+delay() {
+ info "sleeping $DELAY sec between $1"
+ sleep "$DELAY"
+}
+
set_expiration() {
case "$1" in
1|12|24|72) ;; # OK
@@ -63,7 +68,7 @@ add_url() {
}
copy_urls() {
- if ! check_path; then
+ if ! check_path xsel; then
warn "xsel not found in PATH, not copying URL(s) to clipboard"
return
fi
@@ -152,8 +157,7 @@ upload_file() {
fi
if [ "$URLS" != "" ]; then
- info "sleeping $DELAY sec between uploads"
- sleep "$DELAY"
+ delay "uploads"
fi
info "uploading $FILE"
@@ -194,6 +198,8 @@ if ! check_path curl; then
die "can't find curl on PATH (PATH is \"$PATH\")"
fi
+# option string starts with a :, meaning we're responsible for
+# printing our own error messages.
while getopts ":e:gzcvdo:" OPT; do
case "$OPT" in
e) set_expiration "$OPTARG"; opt_e=1 ;;
@@ -207,8 +213,10 @@ while getopts ":e:gzcvdo:" OPT; do
esac
done
+# getopts doesn't remove the args/options for us, so:
shift $(($OPTIND - 1))
+# sanity check options and external binaries' existence.
[ "$GZIP" = 1 -a "$ZIP" = 1 ] && die "can't give both -g and -z"
[ "$GZIP" = 1 -o "$ZIP" = 1 ] && COMPRESS=1
@@ -226,6 +234,7 @@ if [ "$DOWNLOAD" = 1 -o "$ENC" = 1 ]; then
check_path openssl || die "can't find openssl on path, -c/-d won't work"
fi
+# download mode (-d)
if [ "$DOWNLOAD" = 1 ]; then
[ "$GZIP" = 1 ] && warn "-g option ignored when using -d"
[ "$ZIP" = 1 ] && warn "-z option ignored when using -d"
@@ -233,7 +242,9 @@ if [ "$DOWNLOAD" = 1 ]; then
[ "$opt_e" = 1 ] && warn "-e option ignored when using -d"
[ "$DLOUT" != "" ] && exec 1>"$DLOUT" || die "can't redirect stdout"
for arg; do
+ [ "$need_delay" = "1" ] && delay "downloads"
download_and_decrypt "$arg"
+ need_delay=1
done
exit 0
else
@@ -242,6 +253,7 @@ fi
info "expire time set to $( pluralize $EXPIRE hour )"
+# upload mode
[ "$1" = "" ] && set -- -
for arg; do
TMPFILE=""
@@ -253,12 +265,14 @@ for arg; do
FILE="$arg"
compress_file # sets FILE
else
+ # broken symlink, device node, FIFO, ???
warn "$arg not a regular file, ignoring"
continue
fi
upload_file
+ # clean up if needed
if [ "$TMPFILE" != "" ]; then
info "removing temp file $TMPFILE"
rm -f "$TMPFILE"
@@ -309,9 +323,9 @@ input. If no files are given, litterbox reads from standard input.
Directories are uploaded as B<.tar.gz> archives, by default. Files
can be optionally encrypted with AES-256.
-Once a file is uploaded, its URL is printed on stdout. If B<xsel>(1)
-is installed, URLs are also copied to the X paste buffer (separated
-by spaces).
+Once a file is uploaded, its URL is printed on stdout (one per
+line). If B<xsel>(1) is installed and X is running, URLs are also
+copied to the X paste buffer (separated by spaces).
When uploading multiple files, a delay of 2 seconds is added between
uploads, to avoid hammering the site.
@@ -420,6 +434,13 @@ for the encryption key (password), on the process's controlling tty.
This could pose a problem if there's no controlling tty. With
multiple files, you will be prompted separately for each.
+=item B<->
+
+Copying URLs to the copy/paste buffer only works under X11. It might
+be possible to support gpm(8) for the console. If Wayland has an
+xsel-like utility, it could be supported too (the author doesn't use
+Wayland so it's not high on the priority list).
+
=back
=head1 AUTHOR