Skip to content

Instantly share code, notes, and snippets.

@meotimdihia
Forked from alyssaq/config.fish
Created June 26, 2018 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meotimdihia/bf483832c6bd9b4b239ed3ee9a8e67d3 to your computer and use it in GitHub Desktop.
Save meotimdihia/bf483832c6bd9b4b239ed3ee9a8e67d3 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-Z_]+)=(.*)\$/\1/")
set value (echo $e | sed -E "s/^export ([A-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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment