2023-01-25 17:28:34 +04:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
|
|
|
ALIASES=(regmv)
|
|
|
|
if [ "$#" -eq 1 -a "$1" == --nutools-makelinks ]; then
|
|
|
|
# créer les liens
|
|
|
|
scriptname="$(basename "$0")"
|
|
|
|
for alias in "${ALIASES[@]}"; do
|
|
|
|
ln -s "$scriptname" "$alias"
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
source "$(dirname -- "$0")/lib/ulib/auto" || exit 1
|
|
|
|
|
|
|
|
case "$scriptname" in
|
|
|
|
regcp)
|
|
|
|
VERB="copier"
|
|
|
|
CMD=cp
|
|
|
|
;;
|
|
|
|
regmv)
|
|
|
|
VERB="déplacer"
|
|
|
|
CMD=mv
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
function display_help() {
|
|
|
|
uecho "$scriptname: $VERB un fichier vers une destination construite avec une expressions régulière
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
$scriptname REGEXP FILEs....
|
|
|
|
|
2023-02-13 15:22:22 +04:00
|
|
|
NB: l'expression régulière est traitée avec sed, e.g s/FROM/TO/
|
2023-05-16 11:13:58 +04:00
|
|
|
NB: le support de regexp-extended est activé
|
2023-02-13 15:22:22 +04:00
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
-n, --fake
|
|
|
|
Ne pas $VERB, afficher simplement ce qui serait fait"
|
2023-01-25 17:28:34 +04:00
|
|
|
}
|
|
|
|
|
2023-02-13 15:22:22 +04:00
|
|
|
fake=
|
|
|
|
args=(
|
|
|
|
--help '$exit_with display_help'
|
|
|
|
-n,--fake fake=1
|
|
|
|
)
|
2023-01-25 17:28:34 +04:00
|
|
|
parse_args "$@"; set -- "${args[@]}"
|
|
|
|
|
|
|
|
regexp="$1"; shift
|
|
|
|
[ -n "$regexp" ] || die "l'expression régulière est requise"
|
|
|
|
|
|
|
|
for src in "$@"; do
|
2023-05-16 11:13:58 +04:00
|
|
|
dest="$(sed -r "$regexp" <<<"$src")"
|
2023-01-25 17:28:34 +04:00
|
|
|
if [ "$src" == "$dest" ]; then
|
|
|
|
eerror "$src: refus de $VERB le fichier sur lui-même"
|
|
|
|
else
|
|
|
|
estep "$src --> $dest"
|
2023-02-13 15:22:22 +04:00
|
|
|
if [ -z "$fake" ]; then
|
|
|
|
"$CMD" "$src" "$dest" || die
|
|
|
|
fi
|
2023-01-25 17:28:34 +04:00
|
|
|
fi
|
|
|
|
done
|