rename(3tcl)
β¨ rename β the glow-up station for your commands π
okay bestie, so this is rename(3tcl) from the Tcl Built-In Commands manual, and it's literally the makeover montage of Tcl. you get to give a command a whole new name, or, if you're feeling ruthless, you get to delete it entirely. no cap. π
πΈ NAME πΈ
rename β rename or delete a command. that's it, that's the whole job description, and she does it flawlessly. π
β¨ SYNOPSIS β¨
rename oldName newName
two arguments. that's the whole vibe check. π¦
π DESCRIPTION π
so here's the tea, bestie. rename takes the command that used to be called oldName and gives it a whole new identity so it's now called newName. it's giving name change era, and honestly? iconic. β¨
and if newName is an empty string? π that's not a rename, that's a deletion. oldName gets yeeted off the face of the interpreter. periodt.
here's the part you need to know though, because it's lowkey the most important thing: oldName and newName can both include namespace qualifiers β like, the names of the containing namespaces. so you're not just renaming, you can move a command around the namespace tree too. π§
and if you rename a command into a different namespace, then future invocations of it will execute in that new namespace. so the command doesn't just get a new name, it gets a whole new home, and it lives there now. main character relocation energy. π‘π«
oh and the rename command itself returns an empty string as its result. so don't go looking for a return value, there isn't one, she's mysterious like that. π
π EXAMPLE π
okay so the actually slay use case for rename is wrapping the standard Tcl commands with your own monitoring machinery. like, you keep the original command safe under a new name, then you build your own version in front of it that does your little extra thing and then calls the real one. chef's kiss. π₯
say you wanna count how many times the source command gets called:
rename ::source ::theRealSource
set sourceCount 0
proc ::source args {
global sourceCount
puts "called source for the [incr sourceCount]'th time"
uplevel 1 ::theRealSource $args
}
look at that. ::source got moved to ::theRealSource, a counter got set up, and then a brand new ::source proc stepped in wearing the old name like it's a hand-me-down jacket that fits better. every call now bumps the counter and prints, then uplevel 1 ::theRealSource $args sends the actual work to the real one. she's a spy in the original's clothes and she's thriving. πβ¨
π«Ά SEE ALSO π«Ά
go read those too, bestie, they're the supporting cast and they eat every time. π
β KEYWORDS β
- command
- delete
- namespace
- rename
and that's the whole page!! written up for Tcl, in the rename(3tcl) manual β mwah, go rename something, you've got this πππ¦
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1997 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms