DEV Community

loading...

Hugo |> Dev Server Open Browser

Peter Lau
Curious about everything about programming. Open mind to everything unfamiliar with. Raise qarabbit (https://quickanswer.awesomefe.dev/about/) online.
Originally published at quickanswer.awesomefe.dev ・1 min read

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"

Discussion (0)

Forem Open with the Forem app