1

I'm trying to pipe the output of dmenu to surf (browser) in order to browse a selected URL. I'm doing:

cat ~/.surf/bookmarks | dmenu | surf

but surf starts before dmenu has exited with my chosen URL. This means it doesn't open with the correct URL. I don't see what the problem is because dmenu prints the URL to standard output after a choice is made, and surf works taking a URL as its argument. To clarify, the bookmarks file just contains URLs on separate lines.

I'm using this in i3, as a bindsym. I also tried

surf (cat ~/.surf/bookmarks | dmenu)

fish shell syntax, as that is my shell. Thanks in advance.

barters
  • 169
  • 4
  • `and surf works taking a URL as its argument.` You're piping it to stdin though. – tkausl Apr 17 '19 at 16:03
  • maybe `surf $(cat ~/.surf/bookmarks | dmenu)`? – Bodo Apr 17 '19 at 16:10
  • @Bodo thanks it worked! I had tried that with fish shell syntax (as in my terminal). However, it seems i3 exec uses bash. So, your version worked. If you give it as an answer, I'll accept it. – barters Apr 17 '19 at 16:53

1 Answers1

1

As mentioned in tkauusl's comment, surf should get the URL as a command line argument, not piped to stdin.

For bash and POSIX compatible shells you can use this syntax:

surf $(cat ~/.surf/bookmarks | dmenu)

For other shells you might have to use

surf `cat ~/.surf/bookmarks | dmenu`

If the URL can contain spaces, you should quote the result of the command substitution.

surf "$(cat ~/.surf/bookmarks | dmenu)"
Bodo
  • 9,287
  • 1
  • 13
  • 29