#!/bin/bash## Up is a bash function to simplify vertical file system navigation.## ## Copyright (C) 2013 Serge Smeesters## ## 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/.mydir="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd )"[ -d $mydir]||exit 4
configfile="$mydir/spm_namelength_config.sh"if[ -f "$configfile"]then
. "$configfile"elseecho"No config file find :("exit 4
fi
trunc_directory (){local shortsize
((shortsize= sizemax - HASH_SIZE ))local PATTERN="";for i in `seq 1$sizemax`;doPATTERN="${PATTERN}?";done;PATTERN="${PATTERN}*"local filefullpathname
find "$root" -depth -name "$PATTERN"|\whileread filefullpathname ;dolocal filefullname=$(basename "$filefullpathname")local filepath=$(dirname "$filefullpathname")local filename=${filefullname%.*}local filextension=${filefullname##*.}local hashvalue="$(echo "$filename" | md5sum | cut -c1-$HASH_SIZE)"echo"--------------------------------"echo"↓ $filefullname"local filextensionsize=${#filextension}if[$filextensionsize -gt $EXTENTION_MAX_SIZE];thenlocal fileshortfullname="$(echo "$filefullname" | cut -c1-$shortsize)$hashvalue"elselocal newsize
((newsize= shortsize - ( filextensionsize + 1)))local fileshortname="$(echo "$filename" | cut -c1-$newsize)$hashvalue"local fileshortfullname="$fileshortname.$filextension"fiecho"→ $fileshortfullname"local fileshortfullpathname="$filepath/$fileshortfullname"if[ -e "$fileshortfullpathname"];thenecho"Waw... the shorten file seam to yet exists ! :("exit 4
fipushd"$filepath" >/dev/null
echo"mv \"$fileshortfullname\" \"$filefullname\"" >> .namelengthrestore
mv "$filefullname""$fileshortfullname"popd >/dev/null
done}
restore_directory (){local filefullpathname
find "$root" -depth -type f -name ".namelengthrestore"|\whileread filefullpathname ;dolocal filepath=$(dirname "$filefullpathname")pushd"$filepath" >/dev/null
cat .namelengthrestore
. .namelengthrestore
rm .namelengthrestore
popd >/dev/null
done}
main (){if[$# -lt 2];thenecho"Less than 2 arguments :("exit 1
fi# echo "\2ドル : \"2ドル\""local root="$(readlink -f "2ドル")"# echo "root : \"$root\""if[ ! -d "$root"];thenecho"\"$root\" don't appear to be a directory :("exit 1
ficase"1ドル" in
trunc)if[$# -lt 3];thenecho"Trunc need 2 arguments..."exit 2
filocal sizemax="3ドル"if[ ! "$sizemax"];thenexit 1;filocal minsizemax
((minsizemax=5 * HASH_SIZE + EXTENTION_MAX_SIZE ))# echo "A reasonable sizemax should be $minsizemax"if["$sizemax" -lt "$minsizemax"];thenecho"sizemax, $sizemax less then minsizemax, $minsizemax :("exit 1
fi
trunc_directory
;;
restore)
restore_directory
;;
*)echo"Usage: 0ドル {trunc <DIR> <MAXLENGTH> |restore <DIR>} " >&2
exit 1
;;esac}
main "$@"
# Nouvelle version...
Posté par Space_e_man (site web personnel) . En réponse au message Script Bash, tronquer noms de fichiers pour eCryptFS. Évalué à 3.
... beaucoup plus rapide !
Merci à tous :)