Import the remaining utilities.
[utils/utils.git] / ftc
diff --git a/ftc b/ftc
new file mode 100755 (executable)
index 0000000..40db748
--- /dev/null
+++ b/ftc
@@ -0,0 +1,37 @@
+#!/bin/bash
+# ftc <file>: file tree create
+set -e
+
+function ftc_sub {
+if [ -h "$1" ]; then
+       ltarget="$(readlink -- "$1" && echo 'x')"
+       ltarget="${ltarget%
+x}"
+       echo "l ${#ltarget} $ltarget"
+elif [ -f "$1" ]; then
+       if [ -x "$1" ]; then
+               stat --format=$'x %s' -- "$1"
+       else
+               stat --format=$'f %s' -- "$1"
+       fi
+       cat -- "$1"
+       echo
+elif [ -d "$1" ]; then
+       (
+       echo "{"
+       cd -- "$1"
+       unset GLOBIGNORE
+       shopt -s nullglob
+       shopt -s dotglob
+       for entry in *; do
+               echo -n "+ ${#entry} $entry "
+               ftc_sub "$entry"
+       done
+       echo "}"
+       )
+else
+       echo "File of unknown type!" 1>&2
+fi
+}
+
+ftc_sub "$1"