Files
q-tools/anduril/Folder2Array
2014-09-16 10:05:37 +03:00

46 lines
865 B
Bash
Executable File

#!/bin/bash
set -f
MAXDEPTH="-maxdepth 1"
HIDDEN="-not -path */\.*"
KEYS="awk {gsub(/\//,\"_\",\$1);print}"
ME=$( basename "$0" )
HELP='Create an array _index for Anduril of the given folder.
Usage: '$ME' [-anr] [path]
-a Include ".*" hidden files
-n Use number for key
-r Recursively find all files in path, exclude folder names from output
'
while getopts ":anrh" opt; do
case $opt in
a)
HIDDEN=""
;;
n)
KEYS='awk $1=NR'
;;
r)
MAXDEPTH="-type f"
;;
h)
echo "$HELP"
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo "$HELP" >&2
exit 1
;;
esac
done
shift $((OPTIND-1))
INPATH="$1"
[ -z "$INPATH" ] && INPATH=.
echo -e '"Key"'"\t"'"File"'
find "$INPATH" -mindepth 1 $MAXDEPTH $HIDDEN -not -name _index -printf '"%P"\t"%P"\n' \
| sort -V | $KEYS