Score:0

How to return from xdg-open within a shell script

se flag

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.

hr flag
Related: [Regain control after opening firefox via terminal](https://askubuntu.com/questions/802428/regain-control-after-opening-firefox-via-terminal)
vanadium avatar
cn flag
@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.
Score:1
cn flag

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.

lacostenycoder avatar
se flag
output to `/dev/null` is cleanest as it doesn't output anything to the terminal, thank you!
lacostenycoder avatar
se flag
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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.