fish 复用 .bash_profile 里的环境变量,以及 alias 命令别名
vim ~/.config/fish/config.fish
添加以下代码
# REUSE ENVIRONMENT VARIABLES FROM ~/.bash_profile
bash -c '. ~/.bash_profile; env' | while read e
set var (echo $e | sed -E "s/([a-zA-Z0-9_]+)=(.*)\$/\1/")
set value (echo $e | sed -E "s/([a-zA-Z0-9_]+)=(.*)\$/\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")
# escape '(' and ')'
set value (echo $value | sed -E "s/\(/\\\(/g" | 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')"
switch $value
case '`*`';
# executable
set NO_QUOTES (echo $value | sed -E "s/^\`(.*)\`\$/\1/")
set -x $var (eval $NO_QUOTES)
case '*'
# default
switch $var
case 'PWD'
case 'SHLVL'
case '_'
case '*'
set value (echo $value | sed -E "s/\(/\\\(/g" | sed -E "s/\)/\\\)/g")
eval set -xg $var $value
end
end
end
cat ~/.bash_profile| grep "^alias" | source
+V why_null 请备注:from博客园