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

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

Related

Backspace Not Working on VS Code's Bash Terminal

So, I'm new to VS code just installed it and I'm having an issue. The backspace doesn't work in the bash terminal of VS code. The backspace works on the cmd terminal of VS code though.
Not working means when I tap the backspace it prints a white space in the terminal.
Also the backspace key works perfectly fine on Git Bash
I tried googling but didn't find what I was looking for!
Please help.
You can check your TERM by running echo $TERM, but before you do this I suggest you restart your vscode as you have already set the TERM by using the command. I think your TERM was set to something incompatible.
export TERM=xterm will set the emulator to xterm.
Most application will expect that you already have the emulator set to something compatible such as xterm or linux.
For more information regarding what export TERM=xterm does you can check the following answer
Now, if you restart your vscode or terminal inside the vscode, TERM will reset to default and the problem will occur again. Therefore I suggest you add the export TERM=xterm in bash_profile or bashrc.
To add it to bashrc, type following in your terminal:
echo export TERM=xterm >> ~/.bashrc
source ~/.bashrc
go to command palette and select open shortcut key words go to this file and delete all data in this file

Environment Variables macOS & WIndows

In Windows' Environment Variable Tab, the User Variable and System Variables are separated. I have a MacBook Pro and would like to add new 'user' variables like Windows. Is this possible? I mean I found there are temporary variables that can be created in the Terminal, but if that Terminal is closed, the variables are gone. I found a way to do a permanent variable, but do not want to mess things up in the core of the macOS. Are there any recommendations?
If you set variables in the ~/.bash_profile file, they will always exist since this file is automatically run every time you open Terminal.
To edit it:
vim .bash_profile
(i to insert text, esc to exit insert mode, :q! to discard and quit, :x to save and quit)
Then add:
export VARIABLE_NAME=value
Save and quit the editor (:x). Then to check if it worked:
echo $VARIABLE_NAME
When the terminal is bash, editing the .bash_profile works.
If you're using zsh, then edit
~/.zsh and add the command as
""export variableName = value"" in to the file
Now, run
""source ~/.zsh""

Setting environment variables in Yosemite

What is the proper way to modify environment variables like PATH in Yosemite?
This is this question Setting environment variables in OS X? but specifically for yosemite since it doesn't work anymore.
Have you tried editing ~/.bash_profile?
Adding a line like this to bash_profile ought to do it:
export PATH=/usr/local/bin:$PATH
What shell are you using? I'm assuming you're using the default Bash shell. There's also Csh, Ksh, and Zsh.
The Terminal.app on Mac OS X by default starts a new login shell each time a window is open. This means that $HOME/.bash_profile or $HOME/profile is always executed when you open a new terminal window. You can set particular defaults in here. For example, I set PS1 and set -o vi.
NOTE: This may not be the case if you're using other Terminal apps like xterm. These open new terminal windows as just new shells. This means that you may not see the changes made in .bash_profile until you log out and log back in.
You can try editing $HOME/.bashrc and see if that helps.
What about other shells?
If you're using Kornshell (ksh), you need to edit the $HOME/profile and not $HOME/.bash_profile. If you're using Zshell (zsh), you're on your own. It's too wacky to describe here. Read the manpage for zsh and search for ZDOTDIR.
When you run a shell script, the $HOME/.bashrc is executed. Most people put something like this in their .bash_profile, so their .bashrc settings are included in a new terminal window:
[[ -x $HOME/.bashrc ]] && source "$HOME/.bashrc"
Some people set things they want to be set when they run a shell script, for example export $PS4="\$LINENO> ".
The $PATH is a bit different. You can set it in .bash_profile (I would not set it in .bashrc), But, Mac OS X has an automated why on how systemwide paths are set. A file called /etc/paths is used to set the default path for all users using either Bash or Kornshell via the /usr/libexec/path_helper program.
On my Mac, I set my $PATH to:
/usr/local/bin:/usr/share/bin:/bin:/usr/bin:/usr/sbin:/sbin:$HOME/bin
When I install programs, I usually install them under /opt when possible. Then, I link their binaries (where ever they're placed) to /usr/local/bin. This way, I don't have to keep building my PATH. Plus, it allows me to override system defaults. For example, /usr/bin/git is at 1.9.3. while my installed /usr/local/bin/git is at version 2.2.1.
One thing you should not do is modify /etc/profile because changes there may be replaced on OS X upgrades.
The problem is not with environment variables set and accessed from within /bin/bash or /bin/sh, but with envars that should be set for programs NOT executed from the shell; i.e. normal apps executed from the dock or Finder.
After finally getting things right with launchctl in Mavericks, Apple is in the process of changing things again. The useful subcommands of launchctl are now labelled as "legacy subcommands", some of which are no longer supported. That leaves a question mark over the others.
In any case, the most important subcommands are still available for now.
launchctl allows for the setting of the overall environment in which user processes execute. It appears that the overall user environment is inherited by all Terminal processes; i.e. all setenv variables are exported. It's a bit tricky to confirm that. In any case, you will still need your .profile and .bashrc to define functions and aliases, which are not supported by launchctl.
I go to some lengths to ensure that all of my launchctl vars are also defined in my profile. This enables me to set up the same environment on remote or VM linux systems, with a few minor tweaks.
Al of my setup is described in this blog post .
following solution worked for me.
Open Terminal
Click on Terminal Menu at right upper corner.
click on Preferences
Click on General
Change Shell open with to command and put /bin/bash in text box.
Now whatever configuration you do in ~/.bash_profile takes effect. Previously you were not using bash(were using ksh) that is why it was not reading .bash_profile.

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