-
Notifications
You must be signed in to change notification settings - Fork 0
/
trename
executable file
·65 lines (52 loc) · 1.4 KB
/
trename
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
#!/bin/bash
# Restart with wish: \
[ z`uname -o` == zCygwin ] && exec wish $(cygpath -w $0) "$@" || exec tclsh $0 "$@"
package require Tk 8.5
if { [catch {package require Ttk}] } {
puts "NOTE: Using good ol' Motif style - Tile not found. Not a problem except poor look&feel."
}
set filename [lindex $argv 0]
if { $filename == "" } {
puts "Usage: [file tail $argv0] <file to rename>"
exit 1
}
if { ![file exists $filename] } {
puts "Error: file not found"
exit 1
}
entry .e
frame .b
button .b.ok -text "Ok" -command do_rename
button .b.cancel -text "Cancel" -command exit
font create DisplayNameFont {*}[font configure TkFixedFont]
font configure DisplayNameFont -size -20
.e configure -font DisplayNameFont
bind .e <Key-Return> do_rename
bind .e <Key-Escape> exit
pack .e .b -fill x
pack .b.ok .b.cancel -side left
.e insert end $filename
wm geometry . "+500+500"
focus .e
proc do_rename {} {
set new_name [.e get]
if { $new_name == $::filename } {
puts "Name not changed."
exit 0
}
set options ""
if { [file exists $new_name] } {
if { [tk_dialog .ask "Rename overwrite warning" "File '$new_name' exists, do you want to overwrite it?" "" 0 Skip Overwrite] == 0 } {
puts "Renaming cancelled"
exit 0
}
set options -force
}
if { [catch {file rename {*}$options $::filename $new_name} res] } {
puts "ERROR: $res"
exit 1
}
puts "Renamed '$::filename' to '$new_name'"
exit 0
}
# vim: ft=tcl