Reputation: 393
I want to open a terminal session in iTerm2 and send text to rename the window title to "Jupyter Notebook", and then open a Jupyter notebook:
export PROMPT_COMMAND='echo -ne "\033]0;Jupyter Notebook\007"'; VAR="jupyter notebook"; $VAR
However, the above commands will first open a Jupyter Notebook, and then rename the terminal title to "Jupyter Notebook" after I interrupt the notebook session using CMD-C.
How do I rename the window title before the notebook session opens?
Upvotes: 0
Views: 297
Reputation: 393
Solved by creating another environment variable:
TITLE='echo -ne "\033]0;Jupyter Notebook\007"'; $TITLE; VAR="jupyter notebook"; $VAR
But I still don't understand bash's behavior. If I attempt to set a title before running, say, an Apache Spark shell, then bash ignores the echo command and duly fires up a Spark shell:
echo -ne "\033]0;Apache Spark\007"; spark-shell
Last login: Tue Jan 22 11:54:15 on ttys001
MacBook:directory user$ 'echo -ne "\033]0;Apache Spark\007"'; spark-shell
2019-01-22 12:25:25 WARN NativeCodeLoader:62 - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Setting default log level to "WARN".
Apparently, commands that come after the echo command can override the echo. If someone could explain this behavior, I'd really appreciate it.
Upvotes: 0
Reputation: 781096
Don't do this with PROMPT_COMMAND
. It's intended only for updating the prompt or window title to pick up changes that were made during the previous command, such as cd
. It's not executed until the command completes and the shell is about to print the next prompt -- that's why PROMPT
is in the name.
Use an alias or function to update the title and run the command:
alias jnb='echo -ne "\033]0;Jupyter Notebook\007"; jupiter notebook'
Upvotes: 1