edc / bass

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

can't use alias #52

Closed dpinol closed 6 years ago

dpinol commented 6 years ago

Hi, does bass support converting bash alias?

~> bass alias gcb="git pull" bash: line 0: alias: pull: not found exit code: 1 Bass encountered an error!

If I bass the following file... ~> cat kk.sh set -x alias gcb="git pull" alias gcb ...I get:

~> bass ./kk.sh
++ alias 'gcb=git pull'
++ alias
++ gcb
./kk.sh: line 4: gcb: command not found
exit code: 127
Bass encountered an error!

I saw https://github.com/edc/bass/issues/21, but the problem is that alias "xx='echo lol'" is not valid in bash

$ type xx
xx is aliased to `'echo lol''
$ xx
-bash: echo lol: command not found

It should be :

alias xx='echo lol'
⌂66% [dpinyol:~] $ type xx
xx is aliased to `echo lol'
⌂67% [dpinyol:~] $ xx
lol

thanks

edc commented 6 years ago

Glad you find #21 :) I was about the comment that. Let me know if you run into any other issues.

dpinol commented 6 years ago

@edc Hi, why was #52 closed? I understand it describes a common limitation and #21 is also closed

thanks!

edc commented 6 years ago

Sorry for the late response. Your trouble was due to bash not expanding aliases in script mode. You just need to add shopt -s expand_aliases to the beginning of your bash script.

For example:

$ cat kk.sh
shopt -s expand_aliases
set -x
alias gcb="python -V"
alias
gcb

Now this is a valid bash script. If you wish to execute the script, you don't need bass. You just need to bash it:

$ bash kk.sh
+ alias 'gcb=python -V'
+ alias
alias gcb='python -V'
+ python -V
Python 2.7.10

If what you want is to "inherit" the aliases and other environment variables in the script, then you have to source it, just like if your shell is bash:

$ bass source kk.sh
...
$ gcb
Python 2.7.10