I am using tmux on Kubuntu 22.04.1 with ZSH terminal. I have oh-my-zsh with it.
I have enabled tmux plugin of oh-my-zsh.
STEPS TO REPRODUCE:
enable tmux plugin in oh-my-zsh.
copy-paste below code(I have this in my ~/.zshrc) in ~/.zshrc
export ZSH_TMUX_AUTOSTART=true # Automatically starts tmux (default: false)
export ZSH_TMUX_AUTOCONNECT=false # Automatically connect to a previous session if it exits (default: true)
export ZSH_TMUX_AUTOSTART_ONCE=true # Autostart only if tmux hasn't been started previously (default: true)
OBSERVED RESULT:
It keeps creating new-session everytime I open terminal with previous session running.
EXPECTED RESULT:
I want it to kill all session on closing terminal (Konsole application of Kubuntu)
But I don't want it to create new session every time I open terminal. Which means I want only one session(new) running when I open terminal after closing it without connecting to previous session.
How can I stop this?
Related
I am installing nvm inside docker. After I've finished installing it says to run echo ". ~/.nvm/nvm.sh" >> ~/.bash_profile and then close and reopen terminal.
I think the above procedure updates bash profile and let me access nvm.sh from bash with nvm command. But, to do this, I have to close and reopen bash/terminal.
Is there anyway to do this or I've to stop docker container and then run it again?
Maybe this will help with docker, to run scripts in running docker image, you can attach it to bash, reopen the instance with new profile:
docker ps -all #to get container id
docker exec -i -t 38ad5f94df4d /bin/bash
-t container id or container name
~/.bash_profile is sourced only by login instances of bash, presumably thats why they have said you to logout and then login.
If the only change you have made to ~/.bash_profile is adding the . ~/.nvm/nvm.sh, then you can have the same effect as far as the shell is concerned by source-ing the file in the current shell instance:
. ~/.nvm/nvm.sh
This of course covers only the bash's aspect, not docker as a whole.
Normally when I login to my server via putty, I am able to use nvm, grunt, gulp commands but if I connect with php's ssh2 extension or with sshpass through a bash script those commands are not working unless if I execute this commands first:
~/.nvm/nvm.sh
source ~/.profile
nvm current
And this is my ~/.profile file:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
What seems to be issue ? Why I need to execute this commands every time with automation tools such as ssh2 or sshpass ?
My OS is ubuntu 16.04
This has nothing to do with sshpass. You can verify this by running the ssh session without sshpass, and you will see that even if you manually enter the password, it will still not work.
When you run ssh with a command after it, it starts a remote shell that is not connected to a TTY, and that shell is not considered a login shell. For non-login shells, .profile simply isn't run.
The simple solution this problem is to move the environment setup from .profile to .bashrc. .bashrc is run even for non-interactive shells, and so should provide the environment setup you need.
As a side note, why are you using sshpass at all? Why not use the more secure public key authentication?
To clarify, the fact that the shell is not connected to a TTY is unrelated to your problem. At least for openssh, you can tell it to open a TTY even if a command to run is provided by specifying -t on the command line. .profile will still not be run.
I'm trying to start tmux automatically whenever I open a new shell, just note I'm using iTerm on OSX, I've tried putting the following in my .bashrc file:
if [[ ! $TERM =~ screen ]]; then
exec tmux
fi
this doesn't work, though I've tested it on Ubuntu and it works just fine.
Any help appreciated.
with your codes, what happens if you start 10 terminals?
you can check the output of tmux list-sessions to decide if tmux has already started.
Turns out my .bashrc file wasn't loaded properly off the .bash_profile so I just had to move my scripts and settings to .bash_profile
There's possible duplicate but it's closed and unanswered.
As I'm using chef for automation, would be nice to automate tmux launch with pre-launched python web server and second window opened. (this is specifically for my development environment). And only way of doing this probably specifying parameters from command line.
Commands which I want to execute are in window with title "daemon":
source bin/activate
cd project
DEBUG=1 python app.py
I'm unable to find which command line parameters allows to pre-execute commands when launching tmux, and also to open more windows on launch.
You want to create a session without attaching to it (using the -d option), so that you can send additional tmux commands to open the second window before actually attaching.
tmux new-session -t mysession -d 'source bin/activate; cd project; DEBUG=1 python app.py'
tmux new-window -t mysession
tmux attach-session -t mysession
tmux is auto setting RBENV_VERSION when I start tmux...
Anyone know how to stop it?
Because it auto sets it, I need to do
$ export RBENV_VERSION
to unset it and make .ruby-version work. Thx.
tmux itself will never set (or unset) RBENV_VERSION of its own accord. You have some bit of configuration that is causing this.
My guess is that RBENV_VERSION was set when you started your tmux server and that is is now part of the tmux “global environment” (the base environment inherited by all the processes started by tmux). You can check this
tmux show-environment -g | grep RBENV
If it is present there, you can delete it with this command:
tmux set-environment -gu RBENV_VERSION
If you often find yourself starting tmux when RBENV_VERSION is already set (and you do not want it sent “inside” tmux), then you can add the above command to your ~/.tmux.conf file to make sure that it is cleared every time you start a server.
Another possibility is that it is part of your tmux “session environment”; this environment is “layered” atop the global environment to form the environment that is inherited by the processes started for new windows and panes in a session. You can check it with this command (run it inside the session, or add -t sessname to specify a session):
tmux show-environment | grep RBENV
If this is present, you can unset it in a similar way:
tmux set-environment -u RBENV_VERSION
Finally, if the variable is not present in either the global or session environments, then it is probably coming from something in your shell initialization files. By default, tmux starts login shells, so be sure to check the corresponding bits of shell configuration (e.g. .bash_profile, .bash_login, .profile, etc.) as well as any other bits of initialization.