DEV Community

Peter Lau
Peter Lau

Posted on • Originally published at quickanswer.awesomefe.dev

2

Hugo |> Dev Server Open Browser


IF YOU JUST SOLVED SOME PROBLEM, WELCOME TO DM qaRabbit ON TWITTER, OR CREATE A PULL REQUEST IN GITHUB REPO.

Why hugo dev server can't open browser tab automatically?

Modify hugo source code will definitely solve this issue.

Or we can use two simpler ways:

  • use some program to run command hugo server and open_browser in parallel

  • use simple command sleep

Here is the second way on macOS: (open command only works on macOS)

#!/bin/bash

LOCAL_URL=http://localhost:1313

open_browser () {
  duration=${1:-3}
  sleep $duration
  echo 'After '$duration
  # change open command to proper one
  open --new -a "Google Chrome" --args $LOCAL_URL
}

open_browser 1 &
hugo server

Reference:

https://github.com/gohugoio/hugo/issues/6293
https://www.cyberciti.biz/faq/how-to-run-command-or-code-in-parallel-in-bash-shell-under-linux-or-unix/
https://zwbetz.com/open-a-new-google-chrome-tab-or-window-via-command-line-on-mac"

Top comments (0)

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️