Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMike Gerwitz <mike@mikegerwitz.com>2013-05-25 11:09:14 -0400
committerMike Gerwitz <mike@mikegerwitz.com>2013-05-25 11:51:41 -0400
commitc4e460564b30e3f0e9f8eb7f8b500119a896200e (patch)
tree82858516d194679a6940c75aa2c1c361c82f283a /tools
parentd74d93dab4b18139bc34fb7dc44b196c582e4521 (diff)
downloadthoughts-c4e460564b30e3f0e9f8eb7f8b500119a896200e.tar.gz
thoughts-c4e460564b30e3f0e9f8eb7f8b500119a896200e.tar.bz2
thoughts-c4e460564b30e3f0e9f8eb7f8b500119a896200e.zip
Added doc-cp script
Diffstat (limited to 'tools')
-rwxr-xr-xtools/doc-cp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/doc-cp b/tools/doc-cp
new file mode 100755
index 0000000..a21e14d
--- /dev/null
+++ b/tools/doc-cp
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# Copies a html file without its sorting prefix and extension, placing it in its
+# own directory and naming it as an index file if necessary
+#
+# Copyright (C) 2013 Mike Gerwitz
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##
+
+sstrip()
+{
+ base="$( basename "$1" )"
+ a="${base#??-}"
+ echo "${1%/*}/${a%.*}"
+}
+
+[ -n "$2" ] || {
+ echo "Usage: $0 src dest" >&2
+ exit 64
+}
+
+dest="$( sstrip "$2" )"
+
+# if there is a src directory matching the stripped src name, then we shall
+# place the destination file in a subdirectory of that name; this both solves
+# the problem of naming conflicts and maintains the illusion of url rewriting
+# using only the filesystem
+[ -d "$( sstrip "$1" )" ] \
+ && ( test -d "$dest" || mkdir -p "$dest" ) \
+ && dest="$dest/index.html"
+
+cp "$1" "$dest"