2

I noticed that for aliases etc the title of a Terminal tab/window often isn't the same as the command I typed. This is sometimes confusing, especially for long-running processes with similar names.

So how can I configure bash/Terminal in a way which ensures that the window title always reflects the command as typed?

Examples:

  • When I type python -m SimpleHTTPServer and press Return in a Terminal window, the tab of that Terminal window should show "python -m SimpleHTTPServer" immediately.

  • When I type flushdns, which is my alias for sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache and press Return in a Terminal window, the tab of that Terminal window should show "flushdns" immediately.

What I tried:

I tried modifying PS4 to run a command. This works, however it also prints a lot of other garbage, like getting the current git branch and other commands I put in my PS1. If there's a way for PS4 to only run scripts and not output anything (not even line breaks) I'm fine with that too as a solution.

I also tried the various options under Preferences > Profiles > Tab, but it does not allow showing the literal command I just entered.

8
  • What exactly are you trying to accomplish here? Right now you list a lot of things you have (unsuccessfully) tried, but the goal is rather vague. Are you looking for a way to change the tab/window title while a process is running, for ways to set it individually before a process gets launched, or for something else? Can you clarify, ideally with some examples?
    – nohillside
    Apr 5, 2019 at 7:38
  • @nohillside your interpretation is correct. I rephrased the first sentence and made it bold because that's the main thing I'm trying to achieve.
    – Blaise
    Apr 5, 2019 at 9:51
  • Still not clear.... you want to capture the input of a command? For example, the input could be a text file. How would this be beneficial as the Terminal tab
    – Allan
    Apr 5, 2019 at 10:03
  • What you want to do is clear, why you want to do it, and what you want to accomplish isn‘t. Having more details on that might help.
    – nohillside
    Apr 5, 2019 at 12:20
  • @Allan the input as in, the exact command(s) that I typed in a Terminal. I clarified that bit with two examples.
    – Blaise
    Apr 5, 2019 at 13:20

2 Answers 2

1

macOS Catalina (10.15) now uses Zsh, which makes this really easy.

Show the currently running / last run command by disabling auto_title and adding a preexec hook:

# File: ~/.zshrc

DISABLE_AUTO_TITLE="true"

preexec() {
    printf "\e]1;${1}\a"
}
0

Open a Terminal window and go to preferences. Click on Profiles and select Window from the pane, In the Window pane there is an option to show active process name. Check that box and the one under it that says arguments. See image below.

enter image description here

1
  • 1
    This doesn't show the alias name for aliased commands though
    – nohillside
    Apr 6, 2019 at 8:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .