edc / bass

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

Pass bash options through bass #66

Closed iamogbz closed 5 years ago

iamogbz commented 5 years ago

Some scripts depend on the current shell options $- in their logic. Is there a way to pass all the bash options i.e. login, interactive, etc when executed using bass?

edc commented 5 years ago

I am confused. You use bass with fish, so your current shell is fish, and it does not make sense to pass fish's shell option to bash, right? Could you give a concert example to help me understand the use case?

iamogbz commented 5 years ago

I was thinking of translating fish status to bash options. It might not be possible but an example is; when status --is-interactive then $- in the bash script should have the -i option available.

edc commented 5 years ago

A general solution would require quite some work. If all you need is the -i option, I suggest you fork this and do:

1) read status --is-interactive in bass.fish and set an environment variable when you detect the shell is interactive, and 2) in __bass.py, check the environment variable, and if it is set, then invoke bash with -i option.

edc commented 5 years ago

This diff works for me:

index f35a35a..73789aa 100644
--- a/functions/__bass.py
+++ b/functions/__bass.py
@@ -9,6 +9,7 @@ To be used with a companion fish function like this:

 from __future__ import print_function

+import os
 import json
 import subprocess
 import sys
@@ -37,6 +38,8 @@ def gen_script():
         divider,
     )
     args = [BASH, '-c', command]
+    if os.environ['INTERACTIVE_FISH'] == '1':
+        args.insert(1, '-i')
     output = subprocess.check_output(args, universal_newlines=True)
     stdout, new_env, alias = output.split(divider, 2)
     new_env = new_env.strip()
diff --git a/functions/bass.fish b/functions/bass.fish
index e88fdcb..8d91983 100644
--- a/functions/bass.fish
+++ b/functions/bass.fish
@@ -1,4 +1,8 @@
 function bass
+  if status --is-interactive
+    set -x INTERACTIVE_FISH 1
+  end
+
   set __bash_args $argv
   if test "$__bash_args[1]_" = '-d_'
     set __bass_debug
iamogbz commented 5 years ago

Thanks! Will try this out. Still think it'd be useful to for bass to pass the interactive and login options at least.