2019-12-03 13:00:44 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Description: Batch rename selection or current directory with qmv
|
|
|
|
#
|
|
|
|
# Notes:
|
2021-05-15 17:32:01 +00:00
|
|
|
# - Try to mimic current batch rename functionality but with correct
|
|
|
|
# handling of edge cases by qmv or vidir.
|
|
|
|
# - Qmv opens with hidden files if no selection is used. Selected
|
|
|
|
# directories are shown.
|
|
|
|
# - Vidir don't show directories nor hidden files.
|
2019-12-03 13:00:44 +00:00
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: José Neder
|
|
|
|
|
2020-04-24 04:42:24 +00:00
|
|
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
2019-12-03 13:00:44 +00:00
|
|
|
|
2021-05-14 12:03:28 +00:00
|
|
|
if type qmv >/dev/null 2>&1; then
|
2019-12-03 13:00:44 +00:00
|
|
|
batchrenamesel="qmv -fdo -da"
|
|
|
|
batchrename="qmv -fdo -a"
|
2021-05-14 12:03:28 +00:00
|
|
|
elif type vidir >/dev/null 2>&1; then
|
2019-12-03 13:00:44 +00:00
|
|
|
batchrenamesel="vidir"
|
|
|
|
batchrename="vidir"
|
|
|
|
else
|
|
|
|
printf "there is not batchrename program installed."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -s "$selection" ]; then
|
|
|
|
printf "rename selection? "
|
|
|
|
read -r resp
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$resp" = "y" ]; then
|
2019-12-03 13:20:52 +00:00
|
|
|
# -o flag is necessary for interactive editors
|
2019-12-03 13:00:44 +00:00
|
|
|
xargs -o -0 $batchrenamesel < "$selection"
|
2021-03-27 11:37:58 +00:00
|
|
|
|
|
|
|
# Clear selection
|
|
|
|
if [ -p "$NNN_PIPE" ]; then
|
|
|
|
printf "-" > "$NNN_PIPE"
|
|
|
|
fi
|
2019-12-03 13:00:44 +00:00
|
|
|
elif [ ! "$(LC_ALL=C ls -a)" = ".
|
|
|
|
.." ]; then
|
|
|
|
# On older systems that don't have ls -A
|
|
|
|
$batchrename
|
|
|
|
fi
|