- dir="${treeroot%/}/${directory#/}"
-
- find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -printf "directory %P\n" \
- | sort
- find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -printf "video %P\n" \
- | grep -iE "$file_pattern" \
- | sort
- find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -printf "plain %P\n" \
- | grep -viE "$file_pattern" \
- | sort
+ dir="${treeroot%/}${directory%/}"
+
+ case "$order" in
+ Name)
+ find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -print0 \
+ | sort -z \
+ | xargs -0 printf 'directory %s\n'
+
+ find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \
+ | grep -ziE "$file_pattern" \
+ | sort -z \
+ | xargs -0 printf 'video %s\n'
+
+ find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \
+ | grep -zviE "$file_pattern" \
+ | sort -z \
+ | xargs -0 printf 'plain %s\n'
+ ;;
+ Date)
+ find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -print0 \
+ | xargs -0 stat -c '%Z directory %n' \
+ | sort -r |cut -c12-
+
+ find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \
+ | grep -ziE "$file_pattern" \
+ | xargs -0 stat -c '%Y video %n' \
+ | sort -r |cut -c12-
+
+ find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \
+ | grep -zviE "$file_pattern" \
+ | xargs -0 stat -c '%Y plain %n' \
+ | sort -r |cut -c12-
+ ;;
+ Length)
+ find -L "$dir" -mindepth 1 -maxdepth 1 -type d \! -name ".index" -print0 \
+ | sort -z \
+ | xargs -0 printf 'directory %s\n'
+
+ head -qn1 "${dir}"/.index/*.meta \
+ | sort \
+ | cut -f4- \
+ | tr \\n \\0 \
+ | xargs -0 printf 'video %s\n'
+
+ find -L "$dir" -mindepth 1 -maxdepth 1 \! -type d -print0 \
+ | grep -zviE "$file_pattern" \
+ | sort -z \
+ | xargs -0 printf 'plain %s\n'
+ ;;
+ esac