Last active
April 30, 2024 18:48
-
-
Save voidptr/d77a5a527ed2cc06cd277df9ec366f32 to your computer and use it in GitHub Desktop.
Execute Fish Shell from Bash at end of .bashrc -- while being able to invoke Bash shell from fish without re-running Fish -- and without having to use --norc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Many systems, such as Arch, MSys2, Cygwin, etc., need to have Bash interpret | |
# their startup scripts, set Environment variables, etc. Therefore, setting your | |
# default shell to anything other than Bash might not be a good idea. In these | |
# cases, the conventional advice is to append 'exec fish' at the end of your | |
# .bashrc. However, this approach creates another problem; should you need to | |
# drop into Bash to run a bash script, you need to be careful to use | |
# 'bash --norc' every time. Otherwise, Fish will start up again when you don't | |
# want it to. Obviously, this is cumbersome and inefficient. Thus, instead of | |
# doing a naked 'exec fish' at the end of your .bashrc, use the following: | |
## Edited on 4/17/24 with [Ilan's suggestion|https://gist.github.com/voidptr/d77a5a527ed2cc06cd277df9ec366f32?permalink_comment_id=5026742#gistcomment-5026742] | |
if [[ $(ps --no-header --pid=$PPID --format=comm) != "fish" && -z ${BASH_EXECUTION_STRING} ]] | |
then | |
shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION='' | |
exec fish $LOGIN_OPTION | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ouch! Painful! Sorry!