0

I have some shell functions which allow me to quickly open something in my browser, for example:

issue () {
    if [[ -z "$1" ]]
    then
        xdg-open "https://github.com/myname/myrepo/issues/$(git branch | grep '*' | grep -Poh '\d+')"
    else
        xdg-open "https://github.com/myname/myname/issues/$1"
    fi
}

This function loads in my shell startup scripts and it works fine, the repo issue opens in my browser as expected, however I have to manually exit from the function in my terminal with ctrl + c before I'm able to type again in my terminal.

lacostenycoder
  • 328
  • 4
  • 13
  • Related: [Regain control after opening firefox via terminal](https://askubuntu.com/questions/802428/regain-control-after-opening-firefox-via-terminal) – steeldriver Jun 11 '21 at 16:05
  • @steeldriver less applicable here: xdgopen already detaches from the terminal. In my opinion, the terminal is already released here, but is cluttered by the output of the browser. – vanadium Jun 11 '21 at 16:13

1 Answers1

1

xdg-open detaches the command it runs from the terminal, so probably your terminal is freed. Only, you see some output of the browser rather than the command prompt. Just hit Ctrl+L or give the command clear to return to a neat terminal prompt.

You could, for aestetic reasons, redirect terminal output to /dev/null by adding 1>/dev/null 2>&1 after the command. Alternatively, prepend the command with nohup will also work. This immediately detaches the xdgopen command from the terminal and redirects its output.

vanadium
  • 82,909
  • 6
  • 116
  • 186
  • output to `/dev/null` is cleanest as it doesn't output anything to the terminal, thank you! – lacostenycoder Jun 11 '21 at 19:07
  • as per recommended by stack exchange, I tend to wait in case others may provide additional useful answers, though this answer will likely be the best one, thanks – lacostenycoder Jun 11 '21 at 20:06