-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename-gui
executable file
·67 lines (53 loc) · 1.5 KB
/
rename-gui
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
#!/usr/bin/env fish
# rename-gui - Rename a file via a GUI popup.
# Requirements: zenity
set -- script "$(path basename (status filename))"
argparse -n "$script" 'h/help' 'q/quiet' 'e/exact' -- $argv
if set -q _flag_h
echo "$script - Rename a file via a GUI popup."
echo "Usage: $script [arguments]"
echo
echo " -h/--help - Print help and exit."
echo " -q/--quiet - Don't print any output."
echo " -e/--exact - Don't attempt to preserve the file extension."
exit
end
function warn -d "Echo a warning."
set_color yellow
echo "$script: $argv" >&2
set_color normal
end
set input "$argv[1]"
set orig (path basename "$input")
set full_orig (path resolve "$input")
set pext (path extension "$input")
set dir (path dirname "$full_orig")
if not set -q _flag_e
set preserve " (preserving extension)"
end
set new (zenity --entry --title="$script: $orig" --text="Rename '$orig'$preserve to:" --entry-text="$orig" --width=700)
if not test $status -eq '0'
if not set -q _flag_q
warn "Canceled."
end
exit
end
if not set -q _flag_e; and test -z (path extension "$new")
set new "$new$pext"
end
if test "$(path dirname \"$new\")" = '.'
set new "$dir/$new"
end
if test "$full_orig" = "$new"
warn "Source and target are the same; exiting..."
exit 2
end
if test -e "$new"
if not zenity --question --text="File $new already exists; overwrite?"
exit 1
end
end
mv "$full_orig" "$new"
if not set -q _flag_q
warn "$full_orig -> $new"
end