Migrating from ZSH to Fish

One of the main reason I switched from ZSH to Fish is the ability of highlighting command output and the relative small autocomplete, which don’t lag your computer down when you have a few hundreds results like zsh.

But what I didn’t expect is to rewrite my whole .bash_profile in Fish (Fish is not bash, so it doesn’t use Bash syntax, that’s why you can’t source your .bash_profile file), well, that’s not a hard thing. Just need to read the documentation and learn some changes, such as:

export ABC="abc"
# now becomes
set -x ABC abc

If you execute a command during setting value, you need to change the syntax as well:

export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/src"
# now becomes
set -x RUST_SRC_PATH (rustc --print sysroot)/lib/rustlib/src/rust/src

For $PATH, I prefer to use export command separately from set -x, for whatever reason, I like it:

export PATH=new/path:$PATH
# now becomes
set PATH new/path $PATH
export PATH

For aliases, it’s almost the same:

alias vim="emacs"
# now becomes
alias vim "emacs"

If you use tmux, you probably have this in your .bash_profile or .bashrc:

if [ -z "$TMUX" ]; then
  if [ -z "$EMACS" ] && [ -z "$VSCODE" ]; then
    tmux new

Then you need to convert it to Fish, mostly remove the brackets [] and add a test command:

if test -z "$TMUX";
  if test -z "$EMACS"; and test -z "$VSCODE";
    tmux new

And if you use nvm, you hit the wall, since it’s heavily rely on Bash, there are some solutions such as installing bass to be able to run Bash scripts in your Fish config, but even if you go that route, initializing nvm still slowing down your shell startup time.

A better solution is using fash-nvm-fish, it’s a wrapper around nvm, which doesn’t required to parse the env config everytime you start your shell, so it’s fast. The installing process is simple, you can just follow the instruction on the Github repo. I’ll not copy it here.

If your nvm isn’t in the default directory, which is /root/.nvm/, you need to set the NVM_DIR variable, before calling nvm, in my case, it is:

set -gx NVM_DIR /usr/local/opt/nvm/
nvm use 9 --default

That’s it, just a few steps. Happy fishing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: