Giter Site home page Giter Site logo

fish-bax's Introduction

fish-bax Releases

Run bash utilities right from your fish shell.

Bax is a POSIX shell execution wrapper for the fish shell. Use it to run bash utilities, replaying environment changes in fish without leaving the comfort of your session.

Installation

Install with Fisher (recommended):

fisher add jorgebucaran/fish-bax
Not using a package manager?

Copy bax.fish to any directory on your function path.

set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
curl https://git.io/bax.fish --create-dirs -sLo $XDG_CONFIG_HOME/fish/functions/bax.fish

To uninstall, remove the file.

System Requirements

Background

You need to run a script in bash and want to preserve changes in the environment, e.g., modifications to the $PATH, exported and unset variables, and so on. What do you do? Nuke the current session.

$ exec bash -c "$commands; exec fish"

This is not a rare pattern. Fork a POSIX shell, run your scripts there, inherit the environment in fish. And if you're content with that, you're all set. Any caveats? Unfortunately, yes.

For starters, there's no way to preserve the last command exit status in the new shell. You'll lose the entire state of your session; history may not sync up correctly if you have fish running in other terminal tabs, local variables are gone. Fish takes a little while to start up. Moreover, things fish is configured to do on startup like running configuration snippets or displaying a custom greeting, may not be appreciated. If jobs are running in the background, they'll be terminated too.

To solve this problem, Bax runs your commands in bash, captures environment changes and reproduces them in fish, so you don't have to exec-away your session. Now you can have your cake and eat it too.

Usage

Run bash commands.

$ bax export PYTHON=python2

That will set the environment variable PYTHON in your session.

$ env | string match "PYTHON=*"
PYTHON=python2

Use double quotes (or single quotes to avoid variable substitution) to enclose multiple commands separated by a semicolon. Here's an example that downloads the latest Node.js release using creationix/nvm.

$ bax "source ~/.nvm/nvm.sh --no-use; nvm use latest"

Changing the current directory in a subshell leaves you back where you were when you exit. Bax switches directories instead. To move backward through the directory history use cd - or prevd as you usually would.

$ bax cd ~
$ pwd
/Users/jorgebucaran

Bax supports bash aliases too. While it's unrealistic to handle every possible way of defining an alias, typical cases like command shortcuts work out of the box.

$ bax alias g=git
$ g init
Initialized empty Git repository in ~/Code/fish-bax/.git/

Bax is not infallible. Interactive utilities, such as ssh-add are not currently supported.

License

MIT

fish-bax's People

Contributors

jorgebucaran avatar kairyu avatar

Watchers

 avatar

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.