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.

2

1 Answer 1

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.

2
  • output to /dev/null is cleanest as it doesn't output anything to the terminal, thank you! Jun 11, 2021 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 Jun 11, 2021 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .