#!/usr/bin/wish -f

# changing the title and making the window unresizable
wm title . "regexp change"
wm resizable . 0 0

# creating and packing the contents of the window
frame .labels
frame .entries
label .labels.from -text "From:"
entry .entries.from -width 20 -textvariable from
label .labels.to -text "To:"
entry .entries.to -width 20 -textvariable to
button .labels.show -text "Show" -command show
button .entries.change -text "Change" -command change
pack .labels.from .labels.to .labels.show 
pack .entries.from .entries.to .entries.change -fill x
pack .labels .entries -side left

# initialization of the entry fields
set from ".*"
set to "&"

# the function binded with the show button
proc show {} {
    global from
    global to
    set command "for i in *; do echo mv \\\"\$i\\\" \\\"\$(echo \$i | sed 's/$from/$to/')\\\"; done"
    puts [exec bash -c "$command"]
    puts "------------"
}

# the function binded with the change button
proc change {} {
    global from
    global to
    set command "for i in *; do mv \"\$i\" \"\$(echo \$i | sed 's/$from/$to/')\"; done"
    catch {exec bash -c "$command"} { }
}