Let my HOME alone 1/2
This commit is contained in:
parent
2ae37e902e
commit
a83e45df5e
94 changed files with 328 additions and 58 deletions
47
config/scripts/sedrename
Executable file
47
config/scripts/sedrename
Executable file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Rename a list of files with a sed pattern
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 PATTERN [-d] < filelist"
|
||||
echo
|
||||
echo "Arguments:"
|
||||
echo " PATTERN Sed pattern to apply"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -d Dry run"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
pattern="$1"
|
||||
|
||||
dry=1
|
||||
if [[ -n "$2" ]]; then
|
||||
if [[ "$2" = '-d' ]]; then
|
||||
dry=0
|
||||
else
|
||||
usage
|
||||
fi
|
||||
fi
|
||||
|
||||
while read src
|
||||
do
|
||||
dst="$(echo "$src" | sed "$pattern")"
|
||||
if [[ $? != 0 ]]; then
|
||||
echo "ERREUR Invalid sed pattern"
|
||||
exit 2
|
||||
fi
|
||||
if [[ $dry == 0 ]]; then
|
||||
echo "$src" → "$dst"
|
||||
else
|
||||
mv -- "$src" "$dst"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue