Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass bash options through bass #66

Closed
iamogbz opened this issue Jan 23, 2019 · 5 comments
Closed

Pass bash options through bass #66

iamogbz opened this issue Jan 23, 2019 · 5 comments

Comments

@iamogbz
Copy link

iamogbz commented Jan 23, 2019

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
Copy link
Owner

edc commented Jan 28, 2019

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
Copy link
Author

iamogbz commented Jan 29, 2019

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
Copy link
Owner

edc commented Jan 29, 2019

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
Copy link
Owner

edc commented Jan 29, 2019

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
Copy link
Author

iamogbz commented Jan 29, 2019

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

@iamogbz iamogbz closed this as completed Jan 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants