Git Product home page Git Product logo

fish-bash2env's Introduction

fish-bash2env

A lightweight fish plugin to import environment variables modified by given bash command/script, implemented purely in bash (__bash2env.sh) and fish.

Requirements

  • fish
  • bash
  • coreutils (env -0, tr)

Usage

(Install the plugin first to use the bash2env function)

bash2env [-i/--impure] <bash command>

  • -i, --impure: By default bash2env imports only changed environment variables, --impure flag disables this behavior.
$ bash2env source /etc/profile
$ bash2env export x=123
$ echo $x
123
$ # bash2env is just a wrapper that sources outputs of __bash2env.sh
$ bash /path/to/__bash2env.sh  export x=123
set -gx x '123'
Demo

asciicast

Setting fish as default shell(login shell)

Check if fish is installed:

$ chsh -l | grep fish

Change default shell to fish (the path of fish binary might differ):

$ chsh -s /bin/fish

Source /etc/profile with bash2env in your fish config, this ensures PATH and other important environment variables been added to your environment.

# ~/.config/fish/config.fish or /etc/fish/config.fish
if status is-login
    bash2env source /etc/profile
end

# ...

Install

Makefile

$ make FISH_FUNCTION_DIR=~/.config/fish/functions install
$ # or install globally
$ sudo make install
$ sudo make uninstall
$ fisher install EHfive/fish-bash2env
$ fisher remove EHfive/fish-bash2env
$ set -l function_path /path/to/fish-bash2env/functions
$ set fish_function_path $fish_function_path $function_path

Packages

Distribution Repo Package
Arch Linux AUR fish-bash2env

Performance

Time by sourcing /etc/profile on my personal Arch Linux desktop setup.

Test (1000 runs) Time
bash -c "source /etc/profile" 13.0 ms ± 1.7 ms
env -i bash -c "source /etc/profile" 14.1 ms ± 1.8 ms
env -i __bash2env.sh source /etc/profile | fish 16.1 ms ± 1.3 ms
__bash2env.sh source /etc/profile | fish 22.4 ms ± 3.1 ms

Alternatives

Name Note
foreign-env No multiline env value support
bass Supports alias; Uses python, which is heavy and overkill for this task
babelfish Can't transpile some builtin commands (e.g. read)

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.