Tmux window title keeps renaming - bash

Suddenly, both my screen/tmux started changing my windows' names after every command. They keep changing the name to the value of $PROMPT_COMMAND on every single action on the terminal, even after manually renaming them (by Ctrl+A A on screen or Ctrl+B on tmux).
On tmux I already tried to change the tmux.conf settings to disable window auto renaming off, but seems that it was ignored.
I am using bash without the standard /etc/bashrc configuration file. My distro is Fedora 18.

Add the following to your tmux config file:
set-option -g allow-rename off

Put this at the end of the .tmux.conf file:
set-window-option -g automatic-rename off
set-option -g allow-rename off
then reload the tmux config file (ctrl + b > : > source-file ~/.tmux.conf).

First, if l0b0's answer fixed your problem could you please mark it as a solution? Second, for those of use who stumble upon this question and are using fedora 19 this redhat bug report may be of interest. It seems like the default value of $PROMPT_COMMAND set by /etc/bashrc has been changed recently. I reverted to the previous behavior like this:
echo 'printf "\033]0;%s#%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"' > /etc/sysconfig/bash-prompt-screen
chmod a+rx /etc/sysconfig/bash-prompt-screen

Check whether your PS1 (plus PS2, PS3 or PS4 if those are set) is changing the title:
printf %q "$PS1" | grep -F '\\033'

Related

How to elegantly create a Windows shortcut that starts a WSL program under X

I'm struggling a little to launch xfce4-terminal from my WSL installation under VcXsrv from a button on the Windows taskbar. I don't want any DOS box/console/terminal other than the xfce4-terminal when I'm done. I have it working, but man is it ugly. Does anybody have a cleaner way of doing this?
Here is what I got working: I created a windows shortcut on the Desktop with this target (all in one line, broken with newlines for readability here):
C:\Windows\System32\wscript.exe
\\wsl$\Ubuntu-20.04\home\peter\bin\windows\startTerminal.vbs
startTerminal.vbs was inspired by from 10 Ways To Run Batch Files Silently And Hide The Console Window • Raymond.CC (one of the few solutions that didn't require installing a separate program for this!) and it contains:
CreateObject("Wscript.Shell").Run "C:\Windows\System32\wsl.exe -u peter --exec /home/peter/bin/windows/startTerminal.sh",0,True
and startTerminal.sh contains:
export DISPLAY=localhost:0.0
xfce4-terminal --command=/bin/zsh
Setting DISPLAY is apparently required, even though I set the DISPLAY environment in ~/.zshrc. wsl.exe apparently doesn't do that unless you run the login shell.
Once all of this is working, I can drag my shortcut to the taskbar and click on it there.
I count 3, three files cooperating to achieve this simple goal? Can I limit that to one or two without installing an external program?
Yes, I think you can do what I do in one shortcut file. I'll share what works for me then you'll have to fiddle for your program.
Try putting all your commands in the Target section of the Shortcut link file.
Step 1. Right click on desktop then New then Shortcut then name it (LaunchXFCE4)
Step 2. Right click LaunchXFCE4 select Properties
Step 3. Enter all your launch sequences in the Target section
Step 4. Right click LaunchXFCE4 select Pin to Taskbar
I'm launching Emacs 27.1 on WSL 2 with Ubuntu 20.10 on Windows 10 using this code which perhaps you can modify.
C:\Windows\System32\wsl.exe --distribution Ubuntu20 bash -c "export DISPLAY=$(ip route | awk '{print $3; exit}'):0 && export LIBGL_ALWAYS_INDIRECT=1 && export XCURSOR_SIZE=16 && setsid emacs"
The first export display is similar to your localhost:0.0 so replace it or try mine. Maybe your xfce4 replaces my emacs. Read this post about double ampersands. So possibly this
C:\Windows\System32\wsl.exe --distribution Ubuntu20 bash -c "export DISPLAY=localhost:0.0 && export LIBGL_ALWAYS_INDIRECT=1 && export XCURSOR_SIZE=16 && setsid xfce4-terminal --command=/bin/zsh"
Note, my VcXsrv starts when windows starts by putting a shortcut to config.xlaunch in my C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.
By the way, Microsoft will provide a GUI for WSL in a few months, according to their blog
GUI app support in WSL is becoming a reality! We are getting closer to
an initial preview and happy to announce a preview release for Windows
Insiders within the next couple of months.
I removed the need for a startTerminal.sh file by:
Editing startTerminal.vbs to contain:
CreateObject("Wscript.Shell").Run "C:\Windows\System32\wsl.exe -u peter bash -l -c xfce4-terminal",0,True
And then I created a ~/.bash_profile to set the $DISPLAY variable, which probably should've been done anyway:
$ cat .bash_profile
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
So now there is the shortcut and a startTerminal.vbs that starts it up. It still isn't very elegant...
One of the few good additions to Windows was WSL-2, it's much more capable now.
It's part of late Win 10 and Win 11.
Here is how to elegently create a terminal window, replace the terminal with any X app you want.
Linux: "apt-get install xfce4-terminal" (or equivalent)
Windows: Create a new Shortcut (right click in any windows folder)
2.1) Shortcut to -> C:\Windows\System32\wslg.exe -u root -- /usr/bin/xfce4-terminal
If you have multiple distributions use it like: "-d Debian"
That's it. You can give it a better icon and name it.
It will launch the application as if it was a windows application.
After experimenting with #Saj 's answer which did not work for me I resulted in the below:
C:\Windows\System32\wsl.exe --distribution Ubuntu-20.04 bash -c "export DISPLAY=$((route.exe print | Select-String 0.0.0.0 | select -first 1) -Split "\s+" | select -Index 4):0.0 && export LIBGL_ALWAYS_INDIRECT=1 && setsid emacs"
Note that my problem was that it could not use bash commands inside the parenthesis (grep, awk)
Environment: WSL2 on Windows 10

How to reset vim and neovim when sourcing wrong file .zshrc instead of init.vim

I'm using macOS Catalina which has built in Vim 8.1. I'm also using iTerm with zsh and oh-my-zsh. I installed neovim for my personal use and when I setting it up, I accidentally enter source .zshrc in Command mode instead of source init.vim. From then, when I open neovim or built in vim, it does not source init.vim anymore and shows error message like below:
Error detected while processing VIMINIT:
E33: No previous substitute regular expression
Press ENTER or type command to continue
There is a line in my .zshrc that exports VIMINIT variable
export VIMINIT="~/.config/nvim/init.vim"
How can I undo this or is there any other way to reset vim to original setting? Thank you so much
I tried #Niloct solution, unset VIMINIT and vim/neovim is backed to normal. After that, I reopen the iTerm and it showed error message again. Therefore I removed the export line from .zshrc and the problem has been solved.
To load a clean neovim:
nvim -u NONE -U NONE -N -i NONE
Actually I have an alias for that
alias vinone='nvim -u NONE -U NONE -N -i NONE'
This way you can type vinone and use your default neovim

difference between /anaconda3/bin/conda and /anaconda3/condabin/conda

inside shell when
which conda
I get
/anaconda3/bin/conda
while inside tmux I get
/anaconda3/condabin/conda
Anyone knows the difference or something wrong with my config?
Finally I found an answer here that worked for me. Basically as #shouya said there, this problem is because tmux's run-shell command runs a shell which doesn't read from user configs, thus tmux installed in /usr/local/bin will not be found. And best solution is to insert the following line:
set-environment -g PATH "/usr/local/bin:/bin:/usr/bin"
before the first run-shell/run command in your ~/.tmux.conf file, and leave everything else untouched.
Then reload ~/.tmux.conf file by
tmux source-file ~/.tmux.conf

Set Default Shell in Cygwin

I've been using Cygwin for quite a while now. I now want to switch to fish from bash. Everyone is saying that you should use chsh -s /usr/bin/fish, but for some reason, chsh does not work for me. Trying to modify my Cygwin.bat file doesn't work either, and neither does changing my /etc/passwd file.
I really don't understand what's going on. Could someone please help me?
Try editing /etc/nsswitch.conf instead of /etc/passwd
Instead of creating a passwd file, which Cygwin recommends against1, you could edit /etc/nsswitch.conf. Add or edit the following line:
db_shell: /usr/bin/fish
The down/up side of this method is that, if you have multiple users, this change affects all of them. The up/up side is that it's dead simple. The only catch is that you have to restart Cygwin.
If you do use mkpasswd after this change, it will use your new default shell for all users that are allowed to log on.
References
1 The mkpasswd documentation says this:
Don't use this command to generate a local /etc/passwd file, unless you really need one. See the Cygwin User's Guide for more information.
I can't really find any solid reasoning in the user's guide, other than a mention that you'll have to regenerate the /etc/passwd and /etc/group files if your users and groups change, which I suppose is a decent enough reason. I can say that the process is somewhat error prone for newbies.
I randomly meet the same problem, and now I providing my solution for you.
0- Open cygwin by mintty.exe
1- Build passwd file manually (mkpasswd)
$mkpasswd > /etc/passwd
2- Change default shell in passwd file
$vim /etc/passwd
user:*:1976XX:1971XX:U-user\user,S-1-5-21-XXXX:/home/user:/bin/fish
3- Restart mintty.exe
There's an answer on SuperUser that is even simpler. Set the SHELL environment variable in Windows. Set it to your preferred shell (e.g. /bin/tcsh) and newly-launched shells should use it.
To set environment variables:
Go to the "System" control panel (right-click on the Start menu and select "System")
Click on "Advanced system settings" in the left-side column
From the "System Properties" window that pops up, click the "Environment Variables..." button
In either the "User variables" or "System variables" box (depending on whether you want the change to affect just yourself or all users), click the "New..." button.
Type "SHELL" in the "Variable name" box and the path (relative to the Cygwin file system) to your preferred shell in the "Variable value" box.
Click OK on the three open windows to save your changes.
I'm not sure how 'proper' of a solution this is, but I just added /usr/bin/zsh; exit to the bottom of my .bashrc file. You can substitute /usr/bin/zsh for the path to your shell of choice. It seems to work just fine so far.
If you're running Cygwin through ConEmu I found the easiest way is to replace commands line to run fish instead of default shell (Settings->Startup->Tasks):
""c:\cygwin64\bin\fish.exe" --login -i" (please change path to your cygwin folder accordingly)
I wanted to comment on the accepted answer, but not enough rep.
Regarding this method
$ mkpasswd > /etc/passwd
While this works to generate an /etc/passwd file, the odds are you're installing cygwin for yourself, and if your computer belongs to a domain, mkpasswd may run out and attempt to consume the entire domain user list. I had a 500MB+ /etc/passwd file from exactly this condition, and cygwin wouldn't even start until I deleted the file.
I strongly recommend, if using the mkpasswd route to use the -c switch, so it puts an entry in only for yourself.
$ mkpasswd -c > /etc/passwd
On a machine with a shared cygwin service (assuming you have write permissions)
$ mkpasswd -c >> /etc/passwd
I was trying to change my default shell in cygwin to zsh and I found parts of the answers
here helpful, but none of them gave a full solution. The best instructions I found were in the "installing zsh" instruction in the oh my zsh github repo by Robby Russel that you can find here
At the top of the page it has general instructions for installing zsh and then specific instructions for many different platforms. You can scroll down to the Cygwin section and follow the steps:
"The easiest way to change the default shell is to set your SHELL user environment variable. Search for "Edit Environment variables for your account" to bring up the environment variables window, create a new variable named "SHELL" and give it the value "/usr/bin/zsh/"."
(On Windows 7:
Press Windows key.
Start typing "environment".
When it appears, select "Edit environment variables for your account" and add the new variable as stated above.)
After I did this I closed and reopened my Cygwin shell window and tested that it worked with echo $SHELL. Expected result: /bin/zsh or similar.
Hope this helps!
Go to c:\cygwin or c:\cygwin64 (whatever is your cygwin home directory) and edit cygwin.bat. Instead of
bash --login -i
write, for example,
rem bash --login -i
tcsh -l
One simple way to do this is call tcsh at the end of .bashrc file
# x2=$(dirs +${cnt} 2>/dev/null)
# [[ $? -ne 0 ]] && return 0
# [[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}"
# if [[ "${x2}" == "${the_new_dir}" ]]; then
# popd -n +$cnt 2>/dev/null 1>/dev/null
# cnt=cnt-1
# fi
# done
#
# return 0
# }
#
# alias cd=cd_func
tcsh
alias g=gvim
source ~/.cshrc
source ~/.aliases

lose vim colorscheme in tmux mode

I'm running iterm2 and when I'm in tmux mode the colorscheme I have set in vim does not show up. Only the color scheme I've set in iterm. If I run vim from shell the colorscheme appears correct - its only when I'm in tmux mode.
I've tried setting :colorscheme molokai when in vim (see screenshot below) and it doesn't change - again, the default colorscheme for iterm2 remains.
Am I missing some setting to iterm or tmux.conf? My dotfles are up on github here.
I had the same problem. Only difference was I am using solarize rather then molokai.
To fix the issue, I have set up an alias in ~/.bashrc:
alias tmux="TERM=screen-256color-bce tmux"
And set up the default-terminal option in ~/.tmux.conf:
set -g default-terminal "xterm"
Lastly, do $ source ~/.bashrc to load new alias.
I tried all the solutions above and what finally worked for me is putting the following lines in .tmux.conf:
set -g default-terminal "xterm-256color"
As #romainl mentions above, I needed to force tmux to use 256 colors by adding the -2 flag:
$ tmux -2
I added alias tmux='tmux -2' to my bash_profile, so, I don't forget :)
I just discovered why I was having a lot of confusion. I, like others here, was having a difficult time getting the default-terminal setting to take effect. I remembered that I had a tmux session in the background. I re-attached my session, closed out my processes, and closed ALL tmux processes. The next time I restarted tmux the default-terminal setting in .tmux.conf began to take effect. I don't know if others are doing this as well but I recommend closing all tmux processes before modifying the .tmux.conf file.
I got my setup to work on my local machine (OSX 10.9.5 with iTerm2) without any modification to .bashrc or .bash_profile. All I did was add the line set -g default-terminal "xterm-256color" to ~/.tmux.conf and restarted all tmux processes.
I got my remote setup (ssh to Ubuntu 14.04) to work exactly the same way without any modifications to .bashrc. I simply added set -g default-terminal "xterm-256color" to ~/.tmux.conf on my remote machine and restarted all remote tmux processes.
You can test what Vim is seeing by doing echo $TERM from within a tmux session. It kept saying screen as the value until I restarted all tmux processes, at which point it reflected xterm-256color as expected.
Hope that helps.
So this a bit on the stale side, but it's might be worth mentioning that using screen will often break the Home and End keys. Using
export TERM="xterm-256color"
it should keep the functionality of these and allow the color scheme (or powerline) to work fine.
I needed vim to display correctly with tmux in terminal on ubuntu and cygwin/mintty on windows. I got it to work by combining the answers like this.
In .bashrc:
alias tmux="tmux -2"
In .vimrc:
" use 256 colors in terminal
if !has("gui_running")
set t_Co=256
set term=screen-256color
endif
" fix cursor display in cygwin
if has("win32unix")
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
endif
based on answers from this question, this Vim wiki page and this block cursor question
In case anyone needs 24-bit color support:
Tmux supports 24-bit color as of version 2.2. If your terminal supports 24-bit color, add your terminal to the terminal-overrides setting. For example,
set -ga terminal-overrides ",xterm-256color:Tc"
My environment checklist:
macOS Sierra 10.12.3
iTerm2 3.0.14 (Report Terminal Type is xterm-256color)
neovim 0.1.7 (Enable 24-bit color by adding: xterm-256color to .vimrc)
tmux 2.3 (Add set -ga terminal-overrides ",xterm-256color:Tc" to .tmux.conf)
Nothing else I need to add in .bashrc or .zshrc.
Hope this could help.
Since this is the first result on Google and since none of the above helped..wanted to post this so that someone might find it helpful
in .vimrc:
set background=dark
set t_Co=256
HTH
I have tried all of the instructions above, and I found out the most important thing is I have to explicitly add the following line in my .bashrc file.
export TERM=screen-256color
I don't know why alias tmux="TERM=screen-256color-bce tmux" doesn't work out.
I use Sierra 10.12.1.
Just had to deal with this problem, and although all previously posted answers were helpful, they did not solve the issue in my case.
My problem was fixed by removing the following line in my .vimrc:
set termguicolors
which was redondant with another instruction anyway.
Now, with the following line found in previous anwsers in my .tmux.conf:
export TERM="screen-256color"
all is nice and colorful.
Adding the following line in .tmux.conf worked for me with macOS Sierra 10.12.6,
set -g default-terminal "screen-256color"
I'm using gnome terminal and this solved the problem, but (0) don't forget to:
killall tmux
(1) Edit .tmux.conf
# 24 bit color
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"
(2) Edit: .vimrc
" Enable true color
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
Solution posted by rinetd on tmux repo issue:
https://github.com/tmux/tmux/issues/1246
If you find yourself in the same sitation as me, that none of the above worked.. try this:
in .tmux.conf:
set -g default-terminal "xterm"
in bash config (maybe .bashrc or .bash_profile):
alias tmux="tmux -2"
and then run:
killall tmux
and then relaunch tmux
If you use tmuxinator or mux, you will need to add these in .bashrc or .zshrc:
alias tmux='TERM=screen-256color tmux -2'
alias tmuxinator='TERM=screen-256color tmuxinator'
alias mux='TERM=screen-256color mux'
These forces to use 256-color in terminal.
Then tmux, tmuxinator and mux command will all work.
I've removed the line set termguicolors, but it doesn't work.
Setting set notermguicolors instead in the .vimrc works.
In order to set up correct color and to get rid of rendering issue in both Ubuntu and Mac:
check this
From the tmux man page, adding flag as following:
tmux -2
This -2 flag forces tmux to run on 256-color mode.
This works for me
Using these two lines in my .tmux.conf worked for me, I'm using Ubuntu 20.04 with Alacritty.
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",alacritty:RGB"
Found them in an issue on alacitty's repo, in the comment provided by YodaEmbedding:
https://github.com/alacritty/alacritty/issues/109
I didn't have much luck trying to export a different TERM or set default-terminal in my .tmux.conf.
My solution for fixing vim colors within tmux was adding this line to .tmux.conf:
set -g terminal-overrides 'xterm:colors=88'
I'm not sure why this override was needed given that my TERM=xterm and I have iTerm set to xterm as well, but it seems to work.
I am using Ubuntu bionic 18.04.4 LTS and tmux 2.6.
I have the same issue and it can be resolved by simply adding this into .bashrc
export TERM=screen-256color
And ofcourse don't forget to source it.
source ~/.bashrc
Or just restart your teminal
ENV:
Fedora 29 workstation x86_64, GNOME Terminal 3.30.1
VIM - Vi IMproved 8.1 (2018 May 18, compiled Mar 8 2019 09:25:44)
GNU bash, version 4.4.23(1)-release (x86_64-redhat-linux-gnu)
tmux 2.7
vim is using solarized scheme.
.vimrc
...
let g:solarized_termcolors=256
let g:solarized_termtrans=1
syntax enable
set background=dark
colorscheme solarized
...
The value of $TERM in bash is:
[u#loc ~]$ echo $TERM
xterm-256color
[u#loc ~]$ tput colors
256
Mehthod 1: works.
Check $TERM value inside tmux session. Get
[u#loc ~]$ echo $TERM
screen
[u#loc ~]$ tput colors
8
So, just set export TERM=screen-256color inside tmux session. This method only works in the current pane of the session.
Method 2: works.
Create ~/.tmux.conf file and add set -g default-terminal "tmux-256color" to the file.
or Just run echo "set -g default-terminal \"tmux-256color\"" > ~/.tmux.conf
Then kill all tmux sessions.
Start a new session and check the $TERM value inside tmux session. Get
[u#loc ~]$ echo $TERM
tmux-256color
[u#loc ~]$ tput colors
256
And vim colorized scheme works fine for all pane and all tmux sessions.
I also tried xterm-256color and screen-256color in ~/.tmux.conf. They all work fine for colorizing the vim scheme.
By the way, I don't have any configurations being related to this setting in my ~/.bash_profile, ~/.bashrc and ~/.vimrc.
See also https://github.com/tmux/tmux/wiki/FAQ#how-do-i-use-a-256-colour-terminal, https://github.com/tmux/tmux/wiki/FAQ#why-do-you-use-the-screen-terminal-description-inside-tmux
Other useful talks are Vim color scheme changes in tmux #699, 256-color-support-for-vim-background-in-tmux, getting-256-colors-to-work-in-tmux, tmux-term-and-256-colours-support
Assuming that you already have vim colors matching with your terminal:
Kill all tmux sessions running tmux kill-server
Create a user configuration file for tmux in ~/.tmux.conf
Add to the .tmux.conf the following lines:
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",xterm-termite:Tc"
Run in your command line echo $TERM
Replace xterm-termite with the output returned by echo $TERM
I use fedora 34.
I add this to .tmux.conf file
set -g default-terminal "xterm-256color"
Then add this to .vimrc
set background=dark
set t_Co=256

Resources