diff --git a/lib/script.template b/lib/script.template index c977ec5..5e107c5 100755 --- a/lib/script.template +++ b/lib/script.template @@ -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: diff --git a/lib/uinst/conf b/lib/uinst/conf index 7c15978..f5d4c67 100644 --- a/lib/uinst/conf +++ b/lib/uinst/conf @@ -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é diff --git a/regcp b/regcp new file mode 100755 index 0000000..ee3fb27 --- /dev/null +++ b/regcp @@ -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