aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/renamer
blob: 8ea2d928c9c7aadd9e28a6da848cb5330fe963ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env sh

# Description: Batch rename selection or current directory with qmv
#
# Notes:
# - 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.
#
# Shell: POSIX compliant
# Author: José Neder

selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection

if command -v qmv >/dev/null 2>&1; then
	batchrenamesel="qmv -fdo -da"
	batchrename="qmv -fdo -a"
elif command -v vidir >/dev/null 2>&1; then
	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
    # -o flag is necessary for interactive editors
    xargs -o -0 $batchrenamesel < "$selection"
elif [ ! "$(LC_ALL=C ls -a)" = ".
.." ]; then
	# On older systems that don't have ls -A
    $batchrename
fi