You are not logged in.

#1 2020-06-05 11:06:19

vegarab
Member
Registered: 2017-12-22
Posts: 47

[Solved] xdg-open to open text files in terminal vim

I'm attempting to have xdg-open open plain textfiles with terminal vim. I've tried the following:

First setting vim as my default plain/text application:

 xdg-mime default vim.desktop text/plain 

Further I've made a script in /usr/local/bin/st-vim-wrapper:

#!/bin/bash -f
bash -ic 'vim "$@"' vim "$@"

In /usr/share/applications/vim.desktop I've set the following:

TryExec=st-vim-wrapper
Exec=st -e "st-vim-wrapper %F"
Terminal=false

However when I attempt to open a text file through xdg-open it simply opens an st-terminal window and immediately closes it again. Running the wrapper-script directly works fine, also with a file parameter e.g.

st-vim-wrapper textfile.txt

If I attempt to run

st -e "st-vim-wrapper textfile.txt"

directly, it responds "child exited with status 1".

Not sure what is going wrong here.

Last edited by vegarab (2020-06-05 14:23:24)

Offline

#2 2020-06-05 12:42:48

seth
Member
Registered: 2012-09-03
Posts: 51,553

Re: [Solved] xdg-open to open text files in terminal vim

Exec=st -e "st-vim-wrapper %F"

Compare

st -e "vim /path/to/file.txt"

and

st -e vim /path/to/file.txt

Offline

#3 2020-06-05 12:55:35

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,548
Website

Re: [Solved] xdg-open to open text files in terminal vim

In addition to the above - what's the purpose of the wrapper?  You can run vim in st from the desktop file.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2020-06-05 14:25:55

vegarab
Member
Registered: 2017-12-22
Posts: 47

Re: [Solved] xdg-open to open text files in terminal vim

The solution here was to change the .desktop file entry to:

Exec=st -e st-vim-wrapper %F

Thank you, Seth.

Trilby wrote:

In addition to the above - what's the purpose of the wrapper?  You can run vim in st from the desktop file.

Doing that resulted in absolutely nothing (visually) happening when xdg-open attempted to open a textfile.

Offline

#5 2020-06-05 14:28:06

seth
Member
Registered: 2012-09-03
Posts: 51,553

Re: [Solved] xdg-open to open text files in terminal vim

Doing that resulted in absolutely nothing

What was your actual exact attempt and how many quotes where in it?

Offline

#6 2020-06-05 14:34:55

vegarab
Member
Registered: 2017-12-22
Posts: 47

Re: [Solved] xdg-open to open text files in terminal vim

seth wrote:

Doing that resulted in absolutely nothing

What was your actual exact attempt and how many quotes where in it?

I can't find the original SO-post where I found a proposed solution with the wrapper (and an explanation for why you need it, which I didn't truly understand).

TryExec=vim
Exec=st -e vim %F
Terminal=false

gives me no visual feedback when opening a text-file with xdg-open.
After a few attempts, it reverts back to using VSCode to open the files, and I need to apply the xdg-mime command again to revert back to vim.
Simply running

st -e vim \path\to\file.txt 

works totally fine otherwise, so not sure what is causing this.

Offline

#7 2020-06-05 14:43:03

seth
Member
Registered: 2012-09-03
Posts: 51,553

Re: [Solved] xdg-open to open text files in terminal vim

The TryExec line?
(Terminal is false so there will be no tty and just "vim" might error out for that)

Offline

#8 2020-06-05 14:49:28

vegarab
Member
Registered: 2017-12-22
Posts: 47

Re: [Solved] xdg-open to open text files in terminal vim

seth wrote:

The TryExec line?
(Terminal is false so there will be no tty and just "vim" might error out for that)

Setting TryExec to

st -e vim

results in VScode being opened immediately (I assume its setup as a fallback editor).

Anyways, to me, everything is working perfectly fine with my wrapper.

Offline

#9 2020-06-05 14:54:07

seth
Member
Registered: 2012-09-03
Posts: 51,553

Re: [Solved] xdg-open to open text files in terminal vim

Just remove the TryExec line.

Offline

#10 2020-06-05 14:56:09

vegarab
Member
Registered: 2017-12-22
Posts: 47

Re: [Solved] xdg-open to open text files in terminal vim

seth wrote:

Just remove the TryExec line.

It now opens textfiles in vim in st, without using the wrapper!

Where can I find more documentation on these .desktop files? I didn't find the Wiki-entry (https://wiki.archlinux.org/index.php/desktop_entries) very useful in understanding the use of TryExec and Terminal.

Edit: Found this: https://specifications.freedesktop.org/ … -variables

Last edited by vegarab (2020-06-05 14:58:14)

Offline

Board footer

Powered by FluxBB