ajout de regcp et regmv

This commit is contained in:
Jephté Clain 2023-01-25 17:28:34 +04:00
parent 5e33a36bcd
commit 93de256914
3 changed files with 51 additions and 2 deletions

View File

@ -1,7 +1,6 @@
#!/bin/bash
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
urequire DEFAULTS
source "$(dirname -- "$0")/lib/ulib/auto" || exit 1
function display_help() {
uecho "$scriptname:

View File

@ -42,6 +42,7 @@ done
./ulink --nutools-makelinks
./doinplace --nutools-makelinks
./fndate --nutools-makelinks
./regcp --nutools-makelinks
# complétion programmable
rm -f ~/etc/bashrc.d/bash_completion.nutools # renommé

49
regcp Executable file
View File

@ -0,0 +1,49 @@
#!/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....
NB: l'expression régulière est traitée avec sed"
}
args=(--help '$exit_with display_help')
parse_args "$@"; set -- "${args[@]}"
regexp="$1"; shift
[ -n "$regexp" ] || die "l'expression régulière est requise"
for src in "$@"; do
dest="$(sed "$regexp" <<<"$src")"
if [ "$src" == "$dest" ]; then
eerror "$src: refus de $VERB le fichier sur lui-même"
else
estep "$src --> $dest"
"$CMD" "$src" "$dest" || die
fi
done