4

Simplified down, I want to write a shell function which runs a program in a new window. For applications like … emacs, firefox, gitk that can look like this:

myopen() {
  $@
}

But I want to open applications which run in the terminal in a new terminal, e.g. for alsamixer, vim, bash, zsh it should look like

myopen() {
  urxvt -e "$@"
}

I have seen that .desktop files contain the information if they should run in a terminal (for vim / gvim)

[Desktop Entry]
Name=Vim
GenericName=Text Editor
TryExec=vim
Exec=vim %F
Terminal=true

or

[Desktop Entry]
Name=GVim
GenericName=Text Editor
TryExec=gvim
Exec=gvim -f %F
Terminal=false

is there an existing interface to query the Terminal filed (i.e. without using locate and grep to find the .desktop file and parsing them)?

So in quasi code I want to fill the gap in

myopen() {
  TERMINALFIELD=$(xdg-app-uses-terminal $1) # this line is made up
  if [[ TERMINALFIELD == true ]]; then
    urxvt -e "$@"
  else
    $@
  fi
  return $?
}
  • 2
    I'm not sure what you're trying to do. Are you simply looking for a way to make an alias of those commands so they are run in a new terminal program? What terminal program are you using? – Julie Pelletier Dec 25 '16 at 16:10
  • xdg-open is the place to look. – Thomas Dickey Dec 25 '16 at 16:53
  • @Julie Pelletier: kind of. so far I accumulated aliases like vim_newwin='urxvt -e vim', gvim_newwin=gvim - such that any _newwin command would open in a new window. but i'd like something that provides the new window behaviour for any "new" command automatically, without the need for me to manually create the alias and check if i should launch the terminal or not. ("new" as in: unused by me before). and i thought about using a function to avoid piling up tons of aliases. I use urxvt. – pseyfert Dec 25 '16 at 16:56
  • @ThomasDickey: I miss how to use xdg-open for this. afaik xdg-open can be used to open a file with the right application. like xdg-open some.pdf launches a pdf reader, but xdg-open vim doesn't launch vim in a new terminal - i merely get a popup message "/home/pseyfert/vim: file or directory not found". And I don't see any hint for other usages in the man page. – pseyfert Dec 25 '16 at 17:02
4

It looks like gtk-launch will do what you want. It will launch an application using the information in the .desktop file. Here is some relevant information from the man page:

gtk-launch takes at least one argument, the name of the application to launch. The name should match application desktop file name, as residing in /usr/share/application, with or without the '.desktop' suffix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.