2020-04-29
|~1 min read
|163 words
Understanding where you are in your terminal can be a useful piece of information.
While you can always find it by printing the working directory, certain terminals can provide that information for you in the UI.
For example, in iTerm, it can be the name of the window.
To set it, I used the precmd
function in zsh: 1
# use precmd to name the window:
# e.g., /Users/stephen/projects/dotfiles -> ~/p/dotfiles
function precmd() {
window_title="\e]0;${${PWD/#"$HOME"/~}/projects/p}\a"
echo -ne "$window_title"
}
Once you save this function and reload your terminal, you can start to see the results.
Before we made the change:
Once refreshed, the precmd function fired and updated our window immediately:
And it will change anytime the directory changes:
Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!