Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

(I'm talking about the shell Fish, esp. Fish's Fish.)

For Bash/ZSH, I had ~/.profile with some exports, aliases and other stuff.

I don't want to have a separate config for environment variables for Fish, I want to re-use my ~/.profile. How?

In The FAQ, it is stated that I can at least import those via /usr/local/share/fish/tools/import_bash_settings.py, however I don't really like running that for each Fish-instance.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

My current solution (see here for a maybe more recent version):

egrep "^export " ~/.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)

    set -xg $var $value
end
share|improve this answer
add comment

You can't. fish's syntax is too different from Bourne shell (/bin/sh) syntax. This is the same reason you can't use .profile with other non-Bourne-derived shells, such as csh and tcsh.

share|improve this answer
    
I don't want to fully execute .profile. I just want to get all exports from there. One easy way would be to egrep "^export" which would be good enough already for me. Another, more correct solution would be this. Also, I e.g. could run this import_bash_settings.py script which probably does something similar. So, there are obviously many ways to do this. With my question here, I was wondering how others have solved this. –  Albert Jul 11 '12 at 14:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.