edc / bass

Make Bash utilities usable in Fish shell

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

set `$SHELL` to `(which bash)`

despairblue opened this issue · comments

Some tools use $SHELL to find out in which shell their running and what syntax to print. Those tools will output fish syntax in bash when $SHELL is set to fish. One of those tools is opam, the ocaml package manager (see ocaml/opam#2162):

bash: line 0: set: -g: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
bash: line 0: set: -g: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
bash: line 0: set: -g: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
bash: line 0: set: -g: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
bash: line 0: set: -g: invalid option
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
exit code: 2
Bass encountered an error!

The reason I want to use bass for this is, that the bash config works, whereas their shipped fish config breaks the entire shell and they won't be fixing it for the stable release, but only the next major release (ocaml/opam#2255 and ocaml/opam#2884).

I could get this to work by setting and unsetting the $SHELL variable:

  set OLD_SHELL $SHELL
  set SHELL (which bash)

# ...

  set SHELL $OLD_SHELL

I think the trick is tun the tool (like opam) with bass. bass will run the tool in a bash shell, which the tool should see the SHELL set to bash instead of fish. For example:

$ bass echo \$SHELL
/bin/bash

or

/private/tmp $ echo 'import os; print os.environ["SHELL"]' > x.py
/private/tmp $ bass python x.py
/bin/bash

I think the trick is tun the tool (like opam) with bass.

Sorry I don't get that part.

bass echo \$SHELL is outputting fish, which seems the problem.

I just updated to master, and sadly by doing that loosing my local workaround (I somehow patched __bass.py to reset the SHELL variable, but cannot remember how).

$ bass echo \$SHELL
/usr/bin/fish

@edc just a follow up, I also tried the python solution:

$ echo $SHELL
/usr/local/bin/fish
$ echo 'import os; print os.environ["SHELL"]' > x.py
$ bass python x.py
/usr/local/bin/fish