Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have different zsh themes for terminal and iTerm

Here is the problem. I am currently using agnoster theme in zsh. It looks great in iTerm but looks like this in terminal.

Ugly terminal

In other words it looks really ugly. So I am interested in two kinds of solutions:

  1. Have different zsh themes for terminal and iTerm. So I can use agnoster for iTerm and some other theme for terminal. (For example: robbyrussell looks fine in terminal so I would like to have agnoster for iTerm and robbyrussell for terminal.

  2. Make some modifications so that agnoster looks fine in terminal.


I got it to work, apparently I was missing a whitespace in my if condition, that rendered it completely useless. Here is how it looks in my zshrc

if [ "$TERM_PROGRAM" = "Apple_Terminal" ]; then
    ZSH_THEME="robbyrussell"
else
    ZSH_THEME="agnoster"
fi
like image 524
Ankit Sultana Avatar asked Jul 17 '15 07:07

Ankit Sultana


1 Answers

Terminal and iTerm set the environmental variable TERM_PROGRAM.

Terminal : Apple_Terminal

iTerm : iTerm

If you use PathFinder's terminal, TERM_PROGRAM is unset.

Open your oh-my-zsh configuration and use the following construction:

OHMYTHEMES=(
    # your favourite themes
)


[ "$TERM_PROGRAM" = "iTerm" ] && OHMYTHEMES+=agnoster

ZSH_THEME=${OHMYTHEMES[(($RANDOM % ${#OHMYTHEMES} + 1))]} # chooses theme among your favourite randomly

As far as you know what is zsh, I assume you know the least bit of shell scripting and can adjust this to your code.

Related question : Get terminal application name from shell

like image 146
theoden8 Avatar answered Nov 15 '22 10:11

theoden8