Hey everyone! I've got a file full of URLs and descriptions like this: `www.lol.com //description`. I want to set up a way to open those URLs using dmenu. Right now, I'm using this command: `cat ~/world/Documents/bookmarks | ~/.config/sway/scripts/mydmenu -p "Bookmarks:" | xargs -0 -I {} firefox "{}"`. The issue is that when the lines contain spaces, xargs takes the whole line including the description, causing it to fail. What I need is to make dmenu display the entire line but only grab the URL part when I select one. How can I do that?
4 Answers
You can use `cut` to fix this! Try modifying your command like this:
`cat ~/world/Documents/bookmarks | ~/.config/sway/scripts/mydmenu -p "Bookmarks:" | cut -d' ' -f1 | xargs -0 -I {} firefox "{}"`
Basically, this will let you show everything in the dmenu while ensuring only the URL is passed to Firefox. You could also skip `xargs` altogether using this:
`firefox "$(cat ~/world/Documents/bookmarks | ~/.config/sway/scripts/mydmenu -p "Bookmarks:" | cut -d' ' -f1)"`.
Thanks for the tips, everyone! I finally got it working. I just realized I needed to include the 'f1' option in the cut command. Great solution, TechieGuru!
Here's another approach:
```bash
url=$(cat ~/world/Documents/bookmarks | ~/.config/sway/scripts/mydmenu -p "Bookmarks:")
url="${url% ///*}"
firefox "$url"
```
This gets the full line from dmenu first, then trims it down to just the URL before passing it to Firefox.
I recommend using `cut -d' ' -f1` right after dmenu. This tells `cut` to treat spaces as delimiters and grab only the first part which should be the URL.
So instead of using `cat`, you might streamline the command like this instead:
```bash
firefox "$(cut -d' ' -f1 ~/world/Documents/bookmarks | ~/.config/sway/scripts/mydmenu -p "Bookmarks:")"
```
This ensures you're getting the URL after selecting an item without dropping what you want to display in dmenu.
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String