Search code examples
bashshellunixcentos7fish

fish shell login commands keep running on screen or tmux session after login


I've just switched to fish-shell

And I've used the instructions of How do I run a command every login? What's fish's equivalent to .bashrc?

Which means I've moved the commands which i prefer to run upon login from .bashrc to ~/.config/fish/config.fish

But right now the commands keep running if i open screen or tmux session ! but before while i were using the default shell that's was never happens (meant that the commands were only run during the login and never re-run in screen session)

How to avoid this?

Thanks in advance.


Solution

  • You can test for the TERM environmental variable to see if your shell is running in such a session. Both screen and tmux by default set it to 'screen'.

    if not string match --quiet -e $TERM 'screen'
        <your startup scripts>
    end
    

    Note that other useful indicators are whether a shell is interactive or a login shell. You can use status --is-interactive and status --is-login to check for these two states.

    In your specific case, a check for login shell might be what you are looking for:

    if status --is-login
        <your startup scripts>
    end
    

    See https://unix.stackexchange.com/questions/38175/difference-between-login-shell-and-non-login-shell for an explanation.