GithubHelp home page GithubHelp logo

Comments (2)

edc avatar edc commented on July 30, 2024 1

how bass import bash functions to fish when sourcing a file

Bass does not really import bash functions. When you source a bash script in bash, two things can happen:

  1. the script might "launch" other programs to do something;
  2. the script can alter the current bash process to change environment variables (which then get "inherited" by any programs launched by the bash process)

When you source a bash script (e.g. nvm.sh) through bass, bass creates a temporary wrapper bash script that roughly does the following when sourced:

  • read all environment variables and remember them
  • source the original bash script (e.g. nvm.sh)
  • re-read all the environment variables and compare what variables have been changed/added/removed

Bass then launch a bash subprocess and source the above wrapper script.

Now let's look at the two things that original script (nvm.sh) wants to do:

  1. the script might "launch" other programs to do something: this is not impacted.
  2. the script can alter the current bash process to change environment variables: the change is only done to the bash subprocess. However, because the wrapper script monitors the change to the environment variables, the changes are then passed to Bass, and bass will replay the changes in the fish shell.

The reason you have to source nvm every time you use it is because you use nvm through its subcommands (like nvm use). Bass does not import nvm functionality to fish, so Bass still has to invoke the nvm with subcommands in a bash shell. Because Bass has to use a new bash shell subprocess to run the subcommand, it has to ask each subprocess to source nvm.sh to get the nvm functionality before running the subcommand.

Let me know if this makes sense.

from bass.

haoadoreorange avatar haoadoreorange commented on July 30, 2024

Yes totally ! Thanks so much for the explanation ! I close the issue here (:+1:

from bass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.