[SOVED by workaround] Weird issue with xdg-open, rofi and i3
Hi all,
I have the following script, which is in my $PATH
#!/bin/bash
xdg-open "$(locate home media | rofi -threads 0 -width 100 -dmenu -i -p "locate:")"
The idea is that when this runs, rofi starts, and while I type a file name, rofi uses locate to show me the related files. Then I choose the file and it opens with xdg-open:
I have an empty file called test.txt in my home folder. I have set up xdg to open this with nvim:
> xdg-mime query filetype test.txt
inode/x-empty
> xdg-mime query default inode/x-empty
nvim.desktop
So, indeed, if I run `xdg-open test.txt`, it will open with nvim. Same thing with the script, if I run `rofilocate` and choose test.txt with rofi, then the file will open with nvim.
Here's the weird part. In my i3 config, I have this line:
bindsym Control+space exec rofilocate
If I press C-space, search for test.txt and choose it, then it will open with firefox!
I know xdg-open can be a pain, but what the heck.. Any ideas?
Thanks in advance.
Last edited by geo909 (2018-10-25 18:24:25)
Re: [SOVED by workaround] Weird issue with xdg-open, rofi and i3
My guess is, when you run xdg-open with i3 shortcut, your user config for default apps is not used. To confirm try to open same file with xdg-open as root, it should open with firefox.
Re: [SOVED by workaround] Weird issue with xdg-open, rofi and i3
Where do you
set
nvim to be the default for empty files?
"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" - Richard Stallman
Re: [SOVED by workaround] Weird issue with xdg-open, rofi and i3
Thank you for your replies.
Docbroke wrote:
My guess is, when you run xdg-open with i3 shortcut, your user config for default apps is not used. To
confirm try to open same file with xdg-open as root, it should open with firefox.
Yes, kind of. I get this:
sudo xdg-open test.txt
/usr/bin/xdg-open: line 881: x-www-browser: command not found
Running Firefox as root in a regular user's session is not supported. ($XAUTHORITY is /home/jorge/.Xauthority which is owned by jorge.)
/usr/bin/xdg-open: line 881: iceweasel: command not found
/usr/bin/xdg-open: line 881: seamonkey: command not found
/usr/bin/xdg-open: line 881: mozilla: command not found
/usr/bin/xdg-open: line 881: epiphany: command not found
/usr/bin/xdg-open: line 881: konqueror: command not found
[18074:18074:1025/211343.058109:ERROR:zygote_host_impl_linux.cc(89)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
/usr/bin/xdg-open: line 881: chromium-browser: command not found
/usr/bin/xdg-open: line 881: google-chrome: command not found
/usr/bin/xdg-open: line 881: www-browser: command not found
/usr/bin/xdg-open: line 881: links2: command not found
/usr/bin/xdg-open: line 881: elinks: command not found
/usr/bin/xdg-open: line 881: links: command not found
/usr/bin/xdg-open: line 881: lynx: command not found
/usr/bin/xdg-open: line 881: w3m: command not found
xdg-open: no method available for opening 'test.txt'
Trilby wrote:
Where do you
set
nvim to be the default for empty files?
I used xdg-mime. Something like
xdg-mime default inode/x-empty nvim.desktop
I also double-checked that nvim was the default application for empty files and text files in pcmanfm and thunar.
Anyway, that said, I found a workaround. First, I created a script in my PATH called "openwithnvim":
#!/bin/bash
# file openwithnvim
DIR=$(dirname "$1")
lxterminal --working-directory=$DIR -e bash -c "nvim \"$1\" ; bash"
Then, I changed the Exec line in nvim.desktop from
Now, everything opens with nvim, no matter where I open it from, rofi, terminal, file manager, etc.
So, unless you are curious to dig into this more, I consider the issue solved. Thanks again.
Last edited by geo909 (2018-10-25 18:25:38)