Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to use keychain with the fish shell, but I'm not sure how to get fish to load the ~/.keychain/hostname-fish file to set the appropriate environment variables.

In bash, there's the "source" command, but it doesn't exist in fish.

share|improve this question
up vote 5 down vote accepted

Below is what I have in ~/.config/fish/ for your specific example.

set -gx HOSTNAME (hostname)
if status --is-interactive;
    keychain --nogui --clear ~/.ssh/id_rsa
    [ -e $HOME/.keychain/$HOSTNAME-fish ]; and . $HOME/.keychain/$HOSTNAME-fish

The source command is ., which also works in bash.

share|improve this answer
@JohnMetta, see the link in the question and You'll need to install the program. – jamessan Feb 28 '13 at 2:11
Sorry, it was stupid of me to post that. I didn't actually want keychain- I was looking to replace the 'source' command, and didn't actually read. Using . is what I needed. – JohnMetta Mar 1 '13 at 0:17
Fyi, . is deprecated and will be removed in a future version, source is what is recommended. – Elijah Lynn Jun 28 '15 at 19:53
The fish command link should be updated to this one. – Franklin Yu Jul 17 at 6:02

The way recommended on the Keychain documentation page is to put this in

if status --is-interactive
    keychain --eval --quiet --quiet path/to/id_rsa

Then, add this to the top of your script:

source $HOME/.keychain/(hostname)-fish


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .