I’m using XFCE desktop and xfce4-terminal with fish as my shell. This is a really minor thing but noticeable because my prompt shows my
$SHLVL which is useful. But when I start xfce4-terminal,
$SHLVL starts at 2 instead of 1. Any idea what could cause this?
It must be something about my DE or terminal settings, since it properly starts at 1 when I log in to a non-graphical TTY. I think it must be something about my terminal settings because if I run
fish -c 'echo $SHLVL > /tmp/shlvl' from the Application Finder, it outputs 1. There is an xfce4-terminal preference for running the command as a login shell, but that being on or off doesn’t make a difference to the starting
That just shows
fish at the top level. I also checked it with
ps axf and it looks pretty normal to me, with
fish being a child of
/run/current-system/sw/bin/xfce4-terminal and no other parents above that.
However, I had a look at what exactly
/run/current-system/sw/bin/xfce4-terminal is. It’s a symlink to
/nix/store/zgpiyprj40n2lvnzgsdy6c4qfbmjs59y-xfce4-terminal-0.8.10/bin/xfce4-terminal which appears to be a wrapper script:
#! /nix/store/wv35g5lff84rray15zlzarcqi9fxzz84-bash-4.4-p23/bin/bash -e
exec -a "$0" "/nix/store/zgpiyprj40n2lvnzgsdy6c4qfbmjs59y-xfce4-terminal-0.8.10/bin/.xfce4-terminal-wrapped" "$@"
/nix/store/zgpiyprj40n2lvnzgsdy6c4qfbmjs59y-xfce4-terminal-0.8.10/bin/.xfce4-terminal-wrapped appears to be the actual xfce4-terminal binary. Maybe the fact that the terminal is launched through a bash script causes the nested
$SHLVL? I would have thought
exec would take care of that but I don’t know exactly what the rules are for incrementing
$SHLVL. I’m also not sure how I would go about fixing this.
I managed to find a good workaround for this that covers any situation where the terminal app might be launched from another shell. I set the xfce4-terminal “Custom command” option to the path to a bash script called
fish-terminal-launcher which has:
SHLVL=0 exec fish -i
So whenever a terminal window is opened, it launches
SHLVL explicitly set to zero in its parent env, so it gets set to one by
fish and works normally from then on.