My terminal is procrastinating πŸ™„

Reduce terminal instance boot time

I made my terminal boot procrastinate for efficiency!

thefuck

thefuck is brilliant in correcting your previous console command, but the setup takes me nearly 700ms on average. Unthinkable!

From thefuck documentation

Instead of setting it up up front when terminal instance boots up β€” I prefer to set it up when I need it. So I set up this idempotent function:

function fuck {
eval "$(thefuck --alias)"
eval "fuck $@"
}

First time I call fuck in an instance it performs the following operations:

  1. Setup thefuck with fuck alias (overrides this function).
  2. Trigger fuck with all the passed in arguments.

So initial setup time is reduced to 20ms and usage gets the hit of 700ms later, on demand. Second call will not take that hit.

nvm

I chose to add this idem potency to the four major commands I use: node, npm, npx, nvm - but you can easily add more.

Each one of the commands is set up to:

  1. Unset all commands in the list (plus the nvm_load command)
  2. Load up NVM
  3. Call the original command with all arguments

The draw back is that globally installed NPM packages won’t work until you explicitly call one of these method names. On the other hand β€” you can add anything to the list if there’s a command you use often and want to join the party ( yarn etc).

There you go, NVM reduced to 80ms and will only take up your time when needed.

Now that NVM is not included by default, we also need to set it up when entering a directory that contains a .nvmrc file.

cd() {
dir=$@
: ${dir:=~}

builtin cd $dir
if [ -f ".nvmrc" ]; then
nvm use
fi
}

What do you think? Anything slowing you down loading up a terminal instance?

Originally published at https://dev.to on September 15, 2019.