DEV Community

Cover image for One feature I love about Fish (the friendly interactive shell)
metacollective
metacollective

Posted on

One feature I love about Fish (the friendly interactive shell)

FISH Shell

As programmers, we all have our specific choices of tools that we stick by, especially when it comes to using command-line tools. And, as the title of this post says, I am a big fan of FISH shell (integrated with iterm2).
You can find all about FISH and how cool it is in its documentation, but what really impressed me is there functions feature.

At any given time I am working on multiple projects which means I have to switch environments all the time. Each environment comes with its own set of environment variables and managing them was a lot harder till I found functions in fish.

All I have to do is set functions in fish’s config file (usually found here — ~/.config/fish/config.fish) like this -

function setPROJECT1ENV_LOCAL
  set -g -x CMS_AUTH_SECRET secretvalue
  set -g -x AWS_ACCESS_KEY_ID secretkey
  set -g -x AWS_SECRET_ACCESS_KEY moresecretkey
  set -g -x DB_PASSWORD secretpassword
  set -g -x API_KEY moresecretkey
end

function setPROJECT2ENV_LOCAL
  set -g -x CMS_AUTH_SECRET secretvalue2
  set -g -x AWS_ACCESS_KEY_ID secretkey2
  set -g -x AWS_SECRET_ACCESS_KEY moresecretkey2
  set -g -x DB_PASSWORD secretpassword2
  set -g -x API_KEY moresecretkey2
end

function setPROJECT3ENV_LOCAL
  set -g -x CMS_AUTH_SECRET secretvalue3
  set -g -x AWS_ACCESS_KEY_ID secretkey3
  set -g -x AWS_SECRET_ACCESS_KEY moresecretkey3
  set -g -x DB_PASSWORD secretpassword3
  set -g -x API_KEY moresecretkey3
end
Enter fullscreen mode Exit fullscreen mode

Now whenever you have to switch environments, just call function from your fish shell like this -
setPROJECT1ENV_LOCAL or setPROJECT2ENV_LOCAL

FISH set function

Fish env are set

Happy fishing everyone 🐟 😄

Top comments (0)