edc / bass

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

Not clear on how to use this with bash functions. #75

Closed dessalines closed 4 years ago

tbodt commented 5 years ago

I do this with fish functions that look like

function lunch
    bass source build/envsetup.sh \; lunch $argv
    return $status
end
edc commented 4 years ago

@dessalines this is good to close? If not, please provide more details. Thanks!

dessalines commented 4 years ago

If bass isn't going to support bash -> fish functions, then its good to close, and add that as a disclaimer on the readme.

edc commented 4 years ago

Actually bash function should be easily usable as @tbodt pointed out. Another example:

$ cat x.sh
function foo {
  echo 'foo'
}
$ bass source x.sh \; foo
foo

Basically, you source before you invoke the function. Wrap the whole thing in a function/alias if you use it a lot:

$ alias foo 'bass source x.sh \; foo'
$ foo
foo
dessalines commented 4 years ago

I have a .bashrc with many aliases, and functions in it. If I can run bass source .bashrc, and it picks up all the aliases, why shouldn't it be able to handle many functions, if the parsing is that trivial?

edc commented 4 years ago

@dessalines I am not sure I understand your question. But you can use all the functions in .bashrc, as long as you source it first in the same bass call:

bass source ~/.bashrc \; foo

Bass invokes bash behind the scene in non-interactive mode, so it does not source .bashrc automatically, and you'll have to source it manually to use any function in it.

For example, my .bashrc defines a function ll that does ls -l. bass ll will fail, but bass source ~/.bashrc \; ll will work just fine.

$ cat .bashrc
function ll {
  ls -l
}

$ bass ll
bass: ll: command not found

$ bass source .bashrc \; ll
total 8
<snip>
dessalines commented 4 years ago

Bass imports aliases differently than you're describing above, it puts them all as fish aliases.

edc commented 4 years ago

@dessalines you are right. The approach above only works with bash functions. Aliases are imported differently. If an imported alias uses bash functions, then it will break.

My suggestion is to convert the few aliases you rely on into functions, and save them in a new file, say, aliases.sh, and then do bass source foo.sh ; source aliases.sh ; bar, where bar is the converted alias.