edc / bass

Make Bash utilities usable in Fish shell
MIT License
2.2k stars 70 forks source link

Inquiry: using exec as an alternative to bass #67

Closed jorgebucaran closed 5 years ago

jorgebucaran commented 5 years ago

Hi @edc! 👋

I've been running some experiments and noticed I could use exec bash -c ... instead of bass for doing the same thing. I was wondering if you were aware of this or if I was missing something.

exec bash -c "$my_bash_cmds; exec fish"

One thing this code is missing is setting the exit status when bash fails, but I could live without that.

edc commented 5 years ago

Hi @jorgebucaran. That is a nice and elegant solution, and it works well! Thanks for sharing! I will update README to mention that.

The downside I can see is that every time that line is run, you will start a new fish shell. So among other things, it will not have access to variable you set earlier.

 ~/Downloads/imports
$ set x 1
 ~/Downloads/imports
$ echo $x
1
 ~/Downloads/imports
$ exec bash -c "export y=2; exec fish"
Welcome to fish, the friendly interactive shell
 ~/Downloads/imports
$ echo $y
2
 ~/Downloads/imports
$ echo $x

You also cannot use it in a fish function or script, because it will terminate the fish process that is running the function/script.