rename(3tcl)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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