Have different zsh themes for terminal and iTerm - terminal

Here is the problem. I am currently using agnoster theme in zsh. It looks great in iTerm but looks like this in terminal.
In other words it looks really ugly. So I am interested in two kinds of solutions:
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.
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

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

Related

Changing the VSCode integrated shell's prompt on MacOS X

Having just installed VScode I have noticed as it uses Bash by default on OSX, with the shell's default prompt of bash-3.2$; consequently, I cannot see the current working directory. It means having to type 'pwd' and 'ls' quite frequently which is obvious quite tedious.
I have tried changing the default shell in the settings to
"terminal.integrated.shell.osx": "/Applications/Utilities/Terminal.app"
or
"terminal.integrated.shell.osx": "/Applications/iTerm.app"
This doesn't seem to work, have I made a mistake here?
I would also like to know if I am limited to bash, can I configure it to display the working directory instead of simply bash-3.2$ ?
See this screenshot of how the VSCode integrated terminal looks by default
Thanks in advance!
I use Ubuntu, and only add the following lines to the end of ~/.bashrc:
if [ "$TERM_PROGRAM" = "vscode" ]; then
PS1='\$ '
fi
Try it and let me know if it works on your OS.
You can set your prompt to contain the current working directory by defining PS1 as follows:
PS1="\w $"
The $ is just some visual sugar. There all manner of things you can have your prompt display. Put the definition in your ~/.bashrc or ~/.profile for it to be set when you login.
Check out the Controlling the Prompt section of the GNU Bash manual for details.
If you are not accustomed to editing your bash init files you can do it with Visual Studio Code by going to View->Command Palette and execute the following command (one-time only):
Install 'Code' command in path
Then open the integrated terminal and type the following:
code ~/.bashrc
Then add the PS1 definition to the bottom of that file.

How to only use oh my zsh in Iterm2, and not all other terminals also?

After installing oh my zsh and customizing it a little, iTerm2 looks awesome but the default terminal on MacOS looks like crap because it can't load the plugins and I don't want it to. So how can I only use oh-my-zsh on Iterm2?
Sounds difficult to do so. Perhaps you can specify your Terminal to open with bash rather than zsh. Then iterm2 will open with zsh (and oh-my-zsh) and terminal will open with bash.

tmux is not using screen-256color even it is set in the config file

I am trying to get tmux to use screen-256color instead of xterm-256color, as it is not recommended. But when I am not using tmux, I would like to keep it as xterm-256color
A little bit of my setup, I am currently using iTerm2 and ssh to my development linux box, which is using zsh.
In my ~/.zshrc, I have:
export TERM="xterm-256color"
In my ~/.tmux.conf, I have:
set -g default-terminal "screen-256color"
With this configuraiton, without tmux, echo $TERM returns xterm-256color (which is right) and with tmux, echo $TERM is still returning xterm-256color instead of screen-256color.
Is there anything else I need to set in order for this to work?
Thanks!
The reason this does not work as expected is, that the zsh session that is started inside tmux overwrites TERM.
You should not set TERM from within in your shell. TERM is the way the terminal informs the shell and other applications about its capabilities (number of colors, key sequences for special keys, etc.). If you change TERM inside the shell, you change the what features the shell and applications expect from the terminal without the terminal itself knowing about it. Oftentimes this may not be an actual issue, but it is better to change the terminal configuration and set the desired value there.
You already did so when setting screen-256color in the configuration of tmux, which is essentially a terminal emulator, too. To do it for iTerm2 (tested with version 3.0.10):
Open the Preferences dialog (in the Menu: iTerm2 → Preferences, or press ⌘+,).
In the dialog go to Profiles → Terminal.
There you can choose the desired value for TERM under Report Terminal Type.
You could modify your .zshrc file to check if you are running in tmux:
[ -z "$TMUX" ] && export TERM=xterm-256color

OSX terminal colors

I am using the terminal on my Macbook. I changed the bash profile so that the terminal can show colors. I used the code:
export CLICOLOR=1
in the .bash_profile.
But when I log in as the root, my terminal still has no colors showed up. So I was wondering how to show the color in the terminal when I log in as the root?
".bash_profile" is meant for the login shell.
".bashrc" is the file meant for interactive non-login shells.
If you want your "CLICOLOR" environment variable to be picked up, maybe you should modify ".bashrc" to have that export, or you should modify your ".bashrc" to match the answer to this closely related question.

Why am I seeing only 8 colors in terminal (xfce-terminal)?

I'm running Xubuntu 13.04 and I want to use Vim as my default editor for everything. I have downloaded many vim color schemas and tried them out, but all of them don't look like the official screenshot.
For example, vim's own color schema - desert should look like this:
But in my vim, many colors won't display, for example the background.
So this means a fighting with xfce's Terminal and I can't force it to use 256 colors.
the command tput colors gives me
8.
At the same time the code for ((x=0; x<=255; x++));do echo -e "${x}:\033[48;5;${x}mcolor\033[000m";done shows me nice colors. it seems i missed something. If I run
**$ echo $TERM**
I get xterm. It should be 'xterm-256color'
When I try
set term=xterm-256color
and
export TERM=xterm-256color
Then: echo $TERM
I get the message
xterm-256color.
But after signout/signup, I'm still not getting the right colors in Vim. And I see the Xterm is changed to xterm again.
I added:
if $TERM == "xterm-256color" set t_Co=256 endif
and
t_Co=256
to my .vimrc file and it didn't seem to help. Then I customized the xterm entries; added this to ~/.Xdefaults:
*customization: -color
XTerm*termName: xterm-256color
Add this to ~/.xsession to apply to new terminals:
if [ -f $HOME/.Xdefaults ]; then
xrdb -merge $HOME/.Xdefaults
fi
When I changed in preferences of terminal, emulate terminal environment, the 'xterm' to 'xterm-256color'
I get the message:
'*** VTE ***: Failed to load terminal capabilities from '/etc/termcap'
When I check /usr/share/vte/termcap/xterm, the file xterm-256color is missing. Same in folder xterm0.0. I tried to find this file on internet to download and put in the folder, but I couldn't find it.
This is driving me crazy the whole day... Have anyone suggestions?
Quick (Temporary) Way
Enter this whenever you open a new terminal:
export TERM=xterm-256color
Works for as long as the window is open.
Works-but-dirty Way
Append the line above to ~/.bashrc.
The problem with that, though, is that editing $TERM in .bashrc is a bad idea because doing that automatically makes any terminal using bash try to use it regardless of whether it actually supports 256 colors or not (like when SSH-ing or accessing the terminals with Ctrl+Alt+F1 to F6).
What I did, though is that since xfce4-terminal sets the $COLORTERM value to xfce4-terminal, I, instead appended the following to .bashrc:
if [ "$COLORTERM" == "xfce4-terminal" ] ; then
export TERM=xterm-256color
fi
That way, the relevant $TERM edit only happens if you're using xfce4-terminal, which just sets it to xterm anyway (and changing the emulation environment results in that "VTE" message).
References:
https://bbs.archlinux.org/viewtopic.php?id=175581
http://vim.wikia.com/wiki/256_colors_in_vim#Comments
http://promberger.info/linux/2008/04/05/getting-256-color-support-working-for-mutt-in-xfce4-terminal/
http://docs.xfce.org/apps/terminal/getting-started

Resources