At some point I added an ssh-add invocation to my config.fish file. So every time I open a terminal, that runs for a couple of seconds.

Is there a better place to set this, so that it runs upon login? Or do I really do need it to run for every terminal?

2 Answers 2


To run a command only in a login shell in fish, you can use:

if status is-login

You can do this either in your config.fish, which you are currently using, or you could make things more modular by moving that functionality to something like ~/.config/fish/conf.d/01_ssh-add, which will automatically be sourced at startup. The downside is that it can make startup more difficult to debug, if you forget to check conf.d. Once you get used to it, though, I think conf.d is far more idiomatic in fish.


You can make it conditional. Use ssh-add -l to list added keys. If anything is added, it will exit with 0 code, otherwise with 1. I'm not familiar with fish's syntax, but in bash-like shells you could use something like this:

ssh-add -l > /dev/null || ssh-add

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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