Skip to content

Instantly share code, notes, and snippets.

@overtrue
Forked from alyssaq/config.fish
Last active December 6, 2023 05:24
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save overtrue/f7cd321708ba917b8def to your computer and use it in GitHub Desktop.
Save overtrue/f7cd321708ba917b8def to your computer and use it in GitHub Desktop.
config.fish set environment variables from bash_profile
# Fish shell
egrep "^export " ~/.bash_profile | while read e
set var (echo $e | sed -E "s/^export ([A-Za-z_]+)=(.*)\$/\1/")
set value (echo $e | sed -E "s/^export ([A-Za-z_]+)=(.*)\$/\2/")
# remove surrounding quotes if existing
set value (echo $value | sed -E "s/^\"(.*)\"\$/\1/")
if test $var = "PATH"
# replace ":" by spaces. this is how PATH looks for Fish
set value (echo $value | sed -E "s/:/ /g")
# use eval because we need to expand the value
eval set -xg $var $value
continue
end
# evaluate variables. we can use eval because we most likely just used "$var"
set value (eval echo $value)
#echo "set -xg '$var' '$value' (via '$e')"
set -xg $var $value
end
@overtrue
Copy link
Author

overtrue commented Nov 19, 2016

curl -o ~/.config/omf/init.fish https://gist.githubusercontent.com/overtrue/f7cd321708ba917b8def/raw/88d5930885210b9cee49782b4bc9bea8efd746ec/init.fish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment