aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-11-16 11:27:55 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-11-16 11:27:55 +1300
commiteded8d2e0ca3d0dfed73f9bb1dbfc87c38663c26 (patch)
treecf4b3fcb114239f79cd4ec86242f72a015aa1a89
parentUpdate submodules (diff)
downloaddotfiles-eded8d2e0ca3d0dfed73f9bb1dbfc87c38663c26.tar.gz
dotfiles-eded8d2e0ca3d0dfed73f9bb1dbfc87c38663c26.zip
Add sqs(1df)
And a relevant issue
-rw-r--r--ISSUES.markdown2
-rw-r--r--README.markdown1
-rwxr-xr-xbin/sqs25
-rw-r--r--man/man1/sqs.1df14
4 files changed, 42 insertions, 0 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown
index a47092bf..e5a84a79 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -16,3 +16,5 @@ Known issues
it would be great, probably using ImageMagick import(1)
* sxhkd(1) might be nicer than xbindkeys; it's in Debian Testing now
* I don't think that the the timeout for dmp(1df) is working
+* stex(1df) and sqs(1df) both overwrite files without checking, which is a
+ bit rude
diff --git a/README.markdown b/README.markdown
index 7e12562c..40a914cd 100644
--- a/README.markdown
+++ b/README.markdown
@@ -462,6 +462,7 @@ Installed by the `install-bin` target:
* `shb(1df)` attempts to build shebang lines for scripts from the system
paths.
* `spr(1df)` posts its input to the sprunge.us pastebin.
+* `sqs(1df)` chops off query strings from filenames, usually downloads.
* `sshi(1df)` prints human-readable SSH connection details.
* `stex(1df)` strips extensions from filenames.
* `sue(8df)` execs `sudoedit(8)` as the owner of all the file arguments given,
diff --git a/bin/sqs b/bin/sqs
new file mode 100755
index 00000000..4da572ac
--- /dev/null
+++ b/bin/sqs
@@ -0,0 +1,25 @@
+#!/bin/sh
+# Chop a trailing query string off filenames
+
+# Check args
+if [ "$#" -eq 0 ] ; then
+ printf >&2 'Need a filename\n'
+ exit 2
+fi
+
+# Iterate through the given files
+for sn ; do
+
+ # Strip trailing slash if any and then query string
+ dn=${sn%/}
+ dn=${dn%%\?*}
+
+ # Ignore this file if its name wouldn't change
+ [ "$sn" != "$dn" ] || continue
+
+ # Attempt a rename, flag an error if there was one
+ mv -- "$sn" "$dn" || ex=1
+done
+
+# Exit with 1 if there was any failed mv(1) run
+exit "${ex:-0}"
diff --git a/man/man1/sqs.1df b/man/man1/sqs.1df
new file mode 100644
index 00000000..c3b1af55
--- /dev/null
+++ b/man/man1/sqs.1df
@@ -0,0 +1,14 @@
+.TH SQS 1df "November 2016" "Manual page for sqs"
+.SH NAME
+.B sqs
+\- strip query strings from the given filenames if present
+.SH SYNOPSIS
+.B sqs 'foo.php?bar=baz'
+.br
+.B sqs 'foo.php?bar=baz' 'quux.php?wibble&florb=1'
+.SH DESCRIPTION
+.B sqs
+renames any of the files given as its trailing arguments to remove a trailing
+HTTP query string. It is not an error if none of the files have the extension.
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>