diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-11-16 11:27:55 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-11-16 11:27:55 +1300 |
commit | eded8d2e0ca3d0dfed73f9bb1dbfc87c38663c26 (patch) | |
tree | cf4b3fcb114239f79cd4ec86242f72a015aa1a89 /bin | |
parent | Update submodules (diff) | |
download | dotfiles-eded8d2e0ca3d0dfed73f9bb1dbfc87c38663c26.tar.gz dotfiles-eded8d2e0ca3d0dfed73f9bb1dbfc87c38663c26.zip |
Add sqs(1df)
And a relevant issue
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/sqs | 25 |
1 files changed, 25 insertions, 0 deletions
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}" |