83 lines
2.0 KiB
Plaintext
83 lines
2.0 KiB
Plaintext
|
#!/bin/bash
|
||
|
# -*- coding: utf-8 mode: sh -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8
|
||
|
function display_help() {
|
||
|
uecho "$scriptname: déplacer, supprimer, copier un fichier ou un lien
|
||
|
|
||
|
Quand on déplace ou qu'on copie un lien, la destination du lien est mise à jour
|
||
|
|
||
|
USAGE
|
||
|
$scriptname mv files... dest
|
||
|
$scriptname cp files... dest
|
||
|
$scriptname rm files...
|
||
|
|
||
|
OPTIONS
|
||
|
-d UPDATEDIR
|
||
|
Chercher dans UPDATEDIR tous les liens qui pointent vers le fichier
|
||
|
concerné, et mettre à jour ces liens après avoir déplacé le fichier, ou
|
||
|
supprimer ces liens si le fichier est supprimé."
|
||
|
}
|
||
|
|
||
|
SCRIPT_ALIASES=(#alias:command
|
||
|
umove:move
|
||
|
udelete:delete
|
||
|
ucopy:copy
|
||
|
)
|
||
|
CMD_ALIASES=(
|
||
|
mv:move
|
||
|
rm:delete remove:delete del:delete
|
||
|
cp:copy
|
||
|
)
|
||
|
DEFAULT_CMD=move
|
||
|
|
||
|
if [ "$#" -eq 1 -a "$1" == --nutools-makelinks ]; then
|
||
|
# créer les liens
|
||
|
scriptname="$(basename "$0")"
|
||
|
for alias in "${SCRIPT_ALIASES[@]}"; do
|
||
|
alias="${alias%:*}"
|
||
|
ln -s "$scriptname" "$alias"
|
||
|
done
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
source "$(dirname "$0")/lib/ulib/ulib" || exit 1
|
||
|
urequire DEFAULTS
|
||
|
|
||
|
# Traduire le nom du script
|
||
|
for script_alias in "${SCRIPT_ALIASES[@]}"; do
|
||
|
splitpair "$script_alias" src dest
|
||
|
if [ "$scriptname" == "$src" ]; then
|
||
|
eval "set -- $dest \"\$@\""
|
||
|
scriptname=ulink
|
||
|
break
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
args=(--help '$exit_with display_help' -d:,--updatedir: .)
|
||
|
parse_args "$@"; set -- "${args[@]}"
|
||
|
|
||
|
# Traduire la commande
|
||
|
[ -n "$*" ] || set -- "$DEFAULT_CMD"
|
||
|
cmd=
|
||
|
found_cmd=
|
||
|
while [ -z "$found_cmd" ]; do
|
||
|
cmd="$1"; shift; found_cmd=1
|
||
|
[ -n "$cmd" ] || break
|
||
|
|
||
|
for cmd_alias in "${CMD_ALIASES[@]}"; do
|
||
|
splitpair "$cmd_alias" src dest
|
||
|
if [ "$cmd" == "$src" ]; then
|
||
|
eval "set -- $dest \"\$@\""
|
||
|
found_cmd=
|
||
|
break
|
||
|
fi
|
||
|
done
|
||
|
done
|
||
|
|
||
|
case "$cmd" in
|
||
|
"") exit_with display_help;;
|
||
|
move) base_umove ${updatedir:+-d "$updatedir"} "$@";;
|
||
|
delete) base_udelete ${updatedir:+-d "$updatedir"} "$@";;
|
||
|
copy) base_ucopy "$@";;
|
||
|
*) die "$cmd: commande incorrecte";;
|
||
|
esac
|