Add file_utils/prefixsubdirs.sh

This commit is contained in:
Matteo Cypriani 2018-04-11 20:55:01 +02:00
rodzic 79157b7a4f
commit b08187c113
3 zmienionych plików z 75 dodań i 0 usunięć

1
bin/prefixsubdirs Dowiązanie symboliczne
Wyświetl plik

@ -0,0 +1 @@
../file_utils/prefixsubdirs.sh

Wyświetl plik

@ -49,6 +49,28 @@ If you want to integrate it in ROX-Filer:
cp mvparent.sh ~/.config/rox.sourceforge.net/SendTo/.inode_directory/"Move here"
prefixsubdirs.sh
================
The use case for this script is to flatten a file hierarchy, for instance
switching from:
dir1
|-- dirA
|-- dirB
`-- dirC
to:
dir1 ; dirA
dir1 ; dirB
dir1 ; dirC
However, `prefixsubdirs.sh` will only rename the subdirectories (not the
regular files) within the given directories, it will not actually flatten the
hierarchy. You can use `mvparent.sh` for this purpose (see above).
unln.py
=======

52
file_utils/prefixsubdirs.sh Executable file
Wyświetl plik

@ -0,0 +1,52 @@
#!/bin/sh
#
# prefixsubdirs.sh, Copyright © 2018 Matteo Cypriani
#
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
#
# For each directory provided on the command-line, this script prefixes its
# subdirectorie(s) with its name and a separator (" ; " by default).
set -e
#set -x
SEPARATOR=' ; '
MVOPTS='-v'
prefix_subdirs()
(
dir="$1"
cd "$dir"
files="$(echo -- *)"
[ "$files" = '*' ] && return 0
for file in * ; do
[ -d "$file" ] || continue
mv $MVOPTS "$file" "${dir}${SEPARATOR}${file}"
done
)
if [ $# -lt 1 ] ; then
echo "Usage: $(basename "$0") DIRECTORY [DIRECTORY [...]]" >&2
exit 1
fi
while [ -n "$1" ] ; do
dir=$1
shift
if [ ! -d "$dir" ] ; then
printf 'Warning! "%s" is not a directory: ignoring.\n' "$dir" >&2
continue
fi
printf 'Entering "%s" ...\n' "$dir"
prefix_subdirs "$dir"
done
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4