Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourced bash_profile is lost upon restore #94

Closed
matthewbassett opened this issue Aug 6, 2015 · 23 comments
Closed

Sourced bash_profile is lost upon restore #94

matthewbassett opened this issue Aug 6, 2015 · 23 comments

Comments

@matthewbassett
Copy link

I may be doing something wrong here, and please share some wisdom if that is the case. I keep quite a number of handy alias's in my bash_profile, along with a few env variables. When I start up tmux and build my environment, I have no problems, but when I resurrect I lose my sourced bash_profile, as well as a few tmux.conf items such as colors etc. Thanks in advance for any help!

@bruno-
Copy link
Member

bruno- commented Aug 6, 2015

Hmm, that's unusual. Can you please link the content of the following 2 files:

  • ~/.tmux.conf
  • ~/.tmux/resurrect/last

@bruno-
Copy link
Member

bruno- commented Aug 18, 2015

Any updates on this?

@matthewbassett
Copy link
Author

Sorry about that. In the midst of moving across the world (;

Here is my ~/.tmux.conf

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'

# tmux-resurrect specific settings
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-save 'S'
set -g @resurrect-restore 'R'
set -g @resurrect-processes 'mosh iftop bmon docker'
run-shell ~/.tmux/.resurrect/resurrect.tmux

# ENV Variables for tmux
set-option -g default-command $SHELL

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

And here is the output of my ~/.tmux/resurrect/last:

pane    0   0   :moodle_db  1   :*  0   :/private/var/log   0   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.189 | 192.168.0.189 60006
pane    0   0   :moodle_db  1   :*  1   :/Users/matthew.bassett 1   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.189 | 192.168.0.189 60008
pane    0   0   :moodle_db  1   :*  2   :/Users/matthew.bassett 0   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.189 | 192.168.0.189 60010
pane    0   0   :moodle_db  1   :*  3   :/Users/matthew.bassett 0   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.189 | 192.168.0.189 60009
pane    0   0   :moodle_db  1   :*  4   :/  0   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.189 | 192.168.0.189 60007
pane    0   1   :Moodle_web 0   :-  0   :/Users/matthew.bassett 0   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.188 | 192.168.0.188 60006
pane    0   1   :Moodle_web 0   :-  1   :/Users/matthew.bassett 0   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.188 | 192.168.0.188 60007
pane    0   1   :Moodle_web 0   :-  2   :/Users/matthew.bassett 1   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.188 | 192.168.0.188 60010
pane    0   1   :Moodle_web 0   :-  3   :/Users/matthew.bassett 0   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.188 | 192.168.0.188 60008
pane    0   1   :Moodle_web 0   :-  4   :/Users/matthew.bassett 0   mosh-client :/usr/local/Cellar/mobile-shell/1.2.5/bin/mosh-client tislaoda@192.168.0.188 | 192.168.0.188 60009
pane    0   2   :local_host 0   :   0   :/Users/matthew.bassett 0   bash    :
pane    0   2   :local_host 0   :   1   :/Users/matthew.bassett 0   bash    :
pane    0   2   :local_host 0   :   2   :/Users/matthew.bassett 0   bash    :
pane    0   2   :local_host 0   :   3   :/Users/matthew.bassett 1   htop    :htop
pane    0   2   :local_host 0   :   4   :/Users/matthew.bassett 0   bash    :
pane    1   0   :bash   1   :*  0   :/Users/matthew.bassett 1   bash    :
window  0   0   1   :*  8495,254x61,0,0[254x30,0,0{127x30,0,0,1,63x30,128,0,2,62x30,192,0,3},254x30,0,31{127x30,0,31,4,126x30,128,31,5}]
window  0   1   0   :-  a448,254x61,0,0[254x30,0,0{127x30,0,0,6,63x30,128,0,7,62x30,192,0,8},254x30,0,31{127x30,0,31,9,126x30,128,31,10}]
window  0   2   0   :   3c5f,254x61,0,0{127x61,0,0[127x30,0,0,12,127x30,0,31,17],126x61,128,0[126x30,128,0{63x30,128,0,13,62x30,192,0,15},126x30,128,31,14]}
window  1   0   1   :*  5960,80x24,0,0,11
state   0   0

Thanks again for your patience and help, tmux-resurrect is awesome (:
Matt

@bruno-
Copy link
Member

bruno- commented Aug 25, 2015

Hey,
your config looks ok.

Just to check, what's the value of $SHELL inside tmux (check with echo $SHELL)?

Also, why do you have this line set-option -g default-command $SHELL? Tmux manpage states that if unset default-command will default to default-shell option, and default-shell will fallback to $SHELL.

@bruno-
Copy link
Member

bruno- commented Nov 25, 2015

Any updates on this?

@matthewbassett
Copy link
Author

Sorry for the long delay. I don't keep up with my github like I should.
echo $SHELL
gives me: /bin/bash

which is what I would expect to get, and I would assume that would source my ~/.bash_profile but I don't think that is happening.
I have also moved my tmux over to an ubuntu linux server and installed tmux-resurrect, and I am experiencing the same thing there. I'm coping though, it is still useful for the window sizes etc. I can just run a command to source ~/.bash_profile in all my panes.

@cento
Copy link

cento commented Jan 22, 2016

Hi, same problem here

@tessus
Copy link
Contributor

tessus commented Jan 25, 2016

@bruno-

I have the same problem on OSX and instead of my prompt (which is defined in /etc/bashrc), I get the following prompt: bash-3.2$.
Also, none of my aliases are loaded, which means that my .bash_profile is not sourced either.

When I create a new window though, I get my standard prompt and /etc/bashrc and .bash_profile are sourced.

So for whatever reason, /etc/bashrc and .bash_profile are not sourced for the restored windows/panes. echo $SHELL also gives me: /bin/bash

@tessus
Copy link
Contributor

tessus commented Jan 25, 2016

I was able to fix this problem by setting the following in .tmux.conf:

set -g default-command "/bin/bash -l"

This is a workaround and not a fix.

@lukka5
Copy link

lukka5 commented Apr 9, 2016

Same problem here. @tessus workaround did work.

@lwilke
Copy link
Contributor

lwilke commented Dec 7, 2018

Problem is that restore.sh uses exec $tmux_default_command, which in turn falls back to tmux default-shell option if tmux default-command not set. Usuallly default-shell is /bin/bash. But tmux calls this as a login shell. The exec call in restore.sh does not.

From the tmux 2.6 man page
default-shell path
Specify the default shell. This is used as the login shell for new win‐
dows when the default-command option is set to empty, and must be the
full path of the executable. When started tmux tries to set a default
value from the first suitable of the SHELL environment variable, the
shell returned by getpwuid(3), or /bin/sh. This option should be con‐
figured when tmux is used as a login shell.

Solution, use

cache_tmux_default_command() {
local default_shell="$(get_tmux_option "default-shell" "")"
export TMUX_DEFAULT_COMMAND="$(get_tmux_option "default-command" "-l $default_shell")"
}

I will prepare a PR.

@kurko
Copy link

kurko commented Feb 19, 2019

I get this as well. It seems like it is loaded initially, and then it unloads it. In my bash, I have some red chars (not in the image below) that show up initially.

screen shot 2019-02-19 at 19 54 47

Adding set -g default-command "/bin/bash -l" fixes the issue.

@lwilke
Copy link
Contributor

lwilke commented Feb 21, 2019

Could you test with the patch above applied?

@drewmoseley
Copy link

FWIW, in my case this resolved the issue. Thanks.

@bruno- bruno- closed this as completed in 9187f8b Nov 27, 2019
bruno- added a commit that referenced this issue Nov 27, 2019
…fault_shell

Fix #94 start default-shell as login shell.
@bruno-
Copy link
Member

bruno- commented Nov 27, 2019

This issue was auto-closed via PR #281.

@vnagarnaik
Copy link

BTW, the fix in #281 is broken. My tmux config does not set default-command and my default-shell is /usr/bin/fish. fish-shell's exec does not have -l flag.

Since this issue needs to solve bash specific issue, can you add a fix to restore.sh to check for bash before adding -l?

@tessus
Copy link
Contributor

tessus commented Dec 5, 2019

I can start working on this in 1 or 2 hours. Will only take a minute. I create a PR then...

@lwilke
Copy link
Contributor

lwilke commented Dec 5, 2019

True, i did not verify every supported shell. But just for the record fish knows about '-l'. Not sure since then though.

~ fish -l -c "status --is-login && echo yes || echo no"
yes
~ fish -v
fish, version 3.0.2

See here: https://rootnroll.com/d/fish-shell

@vnagarnaik
Copy link

exec provided by fish-shell does not know about -l, since I do not set default-command in my tmux.conf.

The recent change causes restore.sh to run exec -l /usr/bin/fish which fails.

@tessus
Copy link
Contributor

tessus commented Dec 5, 2019

@vnagarnaik please let me know, if #320 works for you

@lwilke
Copy link
Contributor

lwilke commented Dec 5, 2019

Ah i see, yes even in fish 3.0.2.

in scripts/restore.sh
cache_tmux_default_command() {
local default_shell="$(get_tmux_option "default-shell" "")"
export TMUX_DEFAULT_COMMAND="$(get_tmux_option "default-command" "-l default_shell")"
}
pane_creation_command() {
echo "cat '$(pane_contents_file "restore" "${1}:${2}.${3}")'; exec $(tmux_default_command)"
}

So fix might look something like

case "$SHELL" in
*fish) bla=...
*) bla="-l ..."
esac
and use "$bla" in cache_tmux_default_command()

@vnagarnaik
Copy link

@vnagarnaik please let me know, if #320 works for you

I patched in the change, and it does work for me. Thanks!

@tessus
Copy link
Contributor

tessus commented Dec 6, 2019

@vnagarnaik glad to hear it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants