Skip to content

Instantly share code, notes, and snippets.

@larromba
Forked from alyssaq/config.fish
Last active January 10, 2017 10:45
Show Gist options
  • Save larromba/f3e597f8d986574f23cdd7c3c9b6bfa3 to your computer and use it in GitHub Desktop.
Save larromba/f3e597f8d986574f23cdd7c3c9b6bfa3 to your computer and use it in GitHub Desktop.
config.fish set environment variables from bash_profile
set -g -x fish_greeting ''
function fish_prompt
importProfile ~/.bashrc
set_color $fish_color_cwd
echo -n (prompt_pwd)
echo -n (git-radar --fish --fetch)
set_color normal
echo -n ' > '
end
function importProfile
egrep "^export " $argv | while read e
set var (echo $e | sed -E "s/^export ([A-Z_0-9]+)=(.*)\$/\1/")
set value (echo $e | sed -E "s/^export ([A-Z_0-9]+)=(.*)\$/\2/")
# remove comments if existing
set value (echo $value | sed -E "s/# [A-Za-z ]+//g")
# remove surrounding quotes if existing
set value (echo $value | sed -E "s/\"//g")
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment