A lightweight fish plugin to import environment variables modified by given bash command/script, implemented purely in bash (__bash2env.sh) and fish.
- fish
- bash
- coreutils (
env -0
,tr
)
(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'
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
# ...
$ 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
Distribution | Repo | Package |
---|---|---|
Arch Linux | AUR | fish-bash2env |
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 |
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 ) |