-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcase-u.sh
78 lines (78 loc) · 2.52 KB
/
case-u.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/bash
#------------------------------------------------------------------------------#
# Programmed By Liz #
#------------------------------------------------------------------------------#
# filename upper case
#
# 2023-11-01 added FAT function
# 2023-11-02 fixed extension detection
# 2023-11-04 added single file command line processing
#---------------------------------------------------------------- initialization
hdg="case-u"
cat="$HOME/.icons/EMOJI Fav/Cat.png"
err="$HOME/.icons/EMOJI Fav/Skull And Crossbones.png"
# notify-send -i "$cat" "caja" "upper case"
#---------------------------------------------------------------------- function
function fx_case-u ()
{
dir=${src%/*} # directory
fil=${src##*/} # filename
nam=${fil%.*} # name
ext=${fil##*.} # extension
if [[ "$nam" == "$ext" ]] # no extension
then
ext=""
else
ext=${ext,,} # -> lcase
fi
while read -a ary
do
siz=${#ary[*]}
des="$dir/"
for ((i=0;i<siz;i++))
do
tmp=${ary[$i]^^} # upper
if ((i<(siz-1)))
then
des="$des$tmp "
else
des="$des$tmp"
fi
done
if [[ "$ext" != "" ]] # no extension
then
des="$des.$ext"
fi
fst=$(findmnt -no "fstype" --target "$src") # fat detection
if [[ $fst == vfat ]]
then
tmp="$dir/temp"
mv "$src" "$tmp"
src="$tmp"
fi
mv -n "$src" "$des" # move/rename
done <<< $nam
}
#------------------------------------------------------------------ main program
if [[ $CAJA_SCRIPT_SELECTED_FILE_PATHS == "" ]]
then # single file
if [[ $1 == "" ]]
then
notify-send -i "$err" "ERROR!" "nothing to process"
exit 1
fi
# notify-send -i "$cat" "$hdg" "single file"
src="$1"
fx_$hdg
echo "$des"
else # scan files
# notify-send -i "$cat" "$hdg" "caja"
while read src
do
if [[ "$src" != "" ]] # ignore empty lines
then
fx_$hdg
fi
done <<< $CAJA_SCRIPT_SELECTED_FILE_PATHS
fi
#-------------------------------------------------------------------------------