Forem

timreach
timreach

Posted on

How to stop Storybook opening a new webpage on start (automatically with zsh)

This started as a tip for Storybook users but it is probably useful for anyone who uses zsh -

Do you find it annoying that whenever you run $ yarn storybook, Storybook takes the liberty of opening itself in a brand new tab? No fun if you're just restarting it because hot reload isn't working or something.

You may or may not know that there is an option to prevent this from happening: $ yarn storybook --ci will start Storybook but not open a tab. Hoorah.

But even knowing this, I often forget and become annoyed for literally microseconds as I close the superfluous tab. Sure, I could just suck up the minor inconvenience, meditate more, drink less caffeine, get some perspective. Or, I could just automate a fix.

I don't want to impose my preference upon the whole team so I don't want to just add the flag to the scripts definition in package.json so instead let's just configure the terminal to add the flag in automatically.

Simply add the following to your ~/.zshrc

function yarn() {
  if [[ "$1" == "storybook" ]]; then
    command yarn storybook --ci "${@:2}"
  else
    command yarn "$@"
  fi
}
Enter fullscreen mode Exit fullscreen mode

P.S. don't forget to restart your terminal before testing it works...

This basically does a check any time yarn is run and if you're executing storybook will automatically add the flag. I'm sure you can imagine other uses of this pattern for similar issues where you want edit the default way a script executes on your machine but not your team's.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay