You are not logged in.

#1 2012-04-09 21:52:41

aquamongoose
Member
Registered: 2012-04-09
Posts: 3

Starting console applications in xmonad

Hi,
  I am just getting started with xmonad and I really like it, but I have one problem.  If I try to launch any console applications from dmenu (vim, for instance), they don't show up.  When I quit xmonad I find that they have actually started back in the original terminal, and sometimes render it unusable.  Is there some way to launch console applications as their own windows and processes, seperate from the original terminal?  If not, do you just start them from a terminal and then move them to the correct workspace?
  For example, I put anything code that I am working on in workspace 2, but regular terminal sessions in workspace 4.  Is there a way that I can launch vim from dmenu and have it automatically moved to workspace 2, like I have done with gVim?

Offline

#2 2012-04-10 09:26:10

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: Starting console applications in xmonad

I don't think this is possible with dmenu (anyone feel free to correct me if I'm wrong). It has no way of knowing wich terminal if has to launch the application with.

The way I have it configured is to simply have a shortcut assigned in my .xmonad.hs which indicates which terminal the application should be launched with. So for example to open vim in urxvt:

, ((modMask, xK_v), spawn "urxvt -e vim")

Burninate!

Offline

#3 2012-04-10 09:46:10

portix
Member
Registered: 2009-01-13
Posts: 757

Re: Starting console applications in xmonad

You can set up some wrapper scripts that can be launched from dmenu, for example i have a script called xvim in ~/bin/

#!/bin/bash

xterm -class Gvim -e vim "$@"

that starts xterm with the same tags active as gvim. I'm using dwm but this should also work with xmonad, of course ~/bin has to be in $PATH.

Offline

#4 2012-04-10 11:38:03

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

Re: Starting console applications in xmonad

you can put commants like "urxvt -e vim" right into dmenu.

You can then use manageHooks to determine which workspace that terminal should open in.


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

Offline

#5 2012-04-10 11:47:22

owain
Member
Registered: 2009-08-24
Posts: 251

Re: Starting console applications in xmonad

portix wrote:

You can set up some wrapper scripts that can be launched from dmenu, for example i have a script called xvim in ~/bin/

#!/bin/bash

xterm -class Gvim -e vim "$@"

that starts xterm with the same tags active as gvim. I'm using dwm but this should also work with xmonad, of course ~/bin has to be in $PATH.

If you make sure ~/bin comes first in $PATH, then you could just call the script 'vim' - although you'd then need to remember to type /usr/bin/vim if you're not in X for some reason.

Offline

#6 2012-04-10 20:25:56

aquamongoose
Member
Registered: 2012-04-09
Posts: 3

Re: Starting console applications in xmonad

Thanks everyone, those ideas work great.  Now, the only thing I'm wondering is what does the "$@" at the end of portix's command do?

Offline

#7 2012-04-10 20:32:31

portix
Member
Registered: 2009-01-13
Posts: 757

Re: Starting console applications in xmonad

$@ expands the scripts arguments, you can then call the script with

xvim somefilename.txt

Without $@ the filename or other arguments you want to pass to vim will be ignored.

Offline

#8 2012-04-13 10:42:33

beloglazov
Member
From: Melbourne, Australia
Registered: 2012-04-13
Posts: 18
Website

Re: Starting console applications in xmonad

Trilby wrote:

you can put commants like "urxvt -e vim" right into dmenu.

You can then use manageHooks to determine which workspace that terminal should open in.

Hi Trilby, could you please explain how to add commants like "urxvt -e vim" into dmenu? Thanks!

Offline

#9 2012-04-13 10:43:52

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: Starting console applications in xmonad

Why not just use gvim? Disable the menu and scrollbar etc and it won't take more space, but it will look nicer and behave better smile


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#10 2012-04-13 10:46:29

beloglazov
Member
From: Melbourne, Australia
Registered: 2012-04-13
Posts: 18
Website

Re: Starting console applications in xmonad

vim was just an example, I'd like to use this for some other programs like bc, etc.

Offline

#11 2012-04-13 10:57:37

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

Re: Starting console applications in xmonad

beloglazov wrote:

Hi Trilby, could you please explain how to add commants like "urxvt -e vim" into dmenu? Thanks!

I'm not sure I understand - you just type it in.  This doesn't get the autocompletion option.  I suppose you could script that into it, but I wouldn't see the point.  When you type "urxvtc -e" it wouldn't really narrow down the list of possibilities.


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

Offline

#12 2012-04-13 11:16:29

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: Starting console applications in xmonad

Trilby wrote:
beloglazov wrote:

Hi Trilby, could you please explain how to add commants like "urxvt -e vim" into dmenu? Thanks!

I'm not sure I understand - you just type it in.  This doesn't get the autocompletion option.  I suppose you could script that into it, but I wouldn't see the point.  When you type "urxvtc -e" it wouldn't really narrow down the list of possibilities.

let it autocomplete "urxvt" for you, then add the -e vim, then press shift-enter


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#13 2012-04-13 11:37:54

beloglazov
Member
From: Melbourne, Australia
Registered: 2012-04-13
Posts: 18
Website

Re: Starting console applications in xmonad

Mr.Elendig wrote:
Trilby wrote:
beloglazov wrote:

Hi Trilby, could you please explain how to add commants like "urxvt -e vim" into dmenu? Thanks!

I'm not sure I understand - you just type it in.  This doesn't get the autocompletion option.  I suppose you could script that into it, but I wouldn't see the point.  When you type "urxvtc -e" it wouldn't really narrow down the list of possibilities.

let it autocomplete "urxvt" for you, then add the -e vim, then press shift-enter

Thank you guys for the replies. Actually, I didn't know that you type into dmenu a command with arguments smile Anyway, I've a made a small modification of dmenu_run that does what I wanted: you type in a command like bc or top; dmenu auto-completes it; and when you press enter, it runs "urxvt -e <your command>". This helps to avoid typing "urxvt -e" every time. Here is the code:

#!/bin/sh
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
if [ -d "$cachedir" ]; then
	cache=$cachedir/dmenu_run
else
	cache=$HOME/.dmenu_cache # if no xdg dir, fall back to dotfile in ~
fi
if stest -dqr -n "$cache" $PATH; then
	choice="$(stest -flx $PATH | sort -u | tee $cache | dmenu)"
else
	choice="$(dmenu < $cache)"
fi

if [[ $choice ]]; then
    urxvt -e $choice
fi

Offline

#14 2012-04-13 11:45:31

Mr.Elendig
#archlinux@freenode channel op
From: The intertubes
Registered: 2004-11-07
Posts: 4,092

Re: Starting console applications in xmonad

Sidenote: look at the Prompt modules for xmonad.


Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest

Offline

#15 2012-04-13 12:06:08

beloglazov
Member
From: Melbourne, Australia
Registered: 2012-04-13
Posts: 18
Website

Re: Starting console applications in xmonad

Mr.Elendig wrote:

Sidenote: look at the Prompt modules for xmonad.

Thanks, I've just tried XMonad.Prompt.Shell as you suggested. It looks similar, but it doesn't open a new terminal. Do you know if there is any option to do it?

Offline

#16 2012-04-16 02:25:05

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

Re: Starting console applications in xmonad

beloglazov, I think you'll love this.  My edit to the dmenu_run script:

#!/bin/sh
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
if [ -d "$cachedir" ]; then
	cache=$cachedir/dmenu_run
else
	cache=$HOME/.dmenu_cache # if no xdg dir, fall back to dotfile in ~
fi
APP=$(
	IFS=:
	if stest -dqr -n "$cache" $PATH; then
		stest -flx $PATH | sort -u | tee "$cache" | dmenu "$@"
	else
		dmenu "$@" < "$cache"
	fi
)

[[ `grep "$APP" ~/.dmenu_term` ]] && urxvtc -e $APP &
[[ ! `grep "$APP" ~/.dmenu_term` ]] && echo $APP | ${SHELL:-"/bin/sh"} &

Change urxvtc to your terminal of choice, and create a list of programs that need to start in a terminal in ~/.dmenu_term


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

Offline

#17 2012-04-16 13:05:12

beloglazov
Member
From: Melbourne, Australia
Registered: 2012-04-13
Posts: 18
Website

Re: Starting console applications in xmonad

Trilby, nice, thanks! I've made a couple of changes: changed the order (first try to run a program in a normal way), and added the -w option to grep to avoid matching substrings:

#!/bin/sh
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
if [ -d "$cachedir" ]; then
	cache=$cachedir/dmenu_run
else
	cache=$HOME/.dmenu_cache # if no xdg dir, fall back to dotfile in ~
fi
APP=$(
	IFS=:
	if stest -dqr -n "$cache" $PATH; then
		stest -flx $PATH | sort -u | tee "$cache" | dmenu "$@"
	else
		dmenu "$@" < "$cache"
	fi
)

[[ ! `grep -w "$APP" ~/.config/dmenu/urxvt-list` ]] && echo $APP | ${SHELL:-"/bin/sh"} &
[[ `grep -w "$APP" ~/.config/dmenu/urxvt-list` ]] && urxvtc -e $APP &

BTW, thanks for pointing to urxvtc, I've switched to the daemon version of urxvt from the regular one.

Offline

#18 2012-04-16 13:22:24

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

Re: Starting console applications in xmonad

Nice, I'll definitely add the -w switch.  BTW, that should have been directed to aquamongoose.  I was confused about who the OP was.  In any case, it's for anyone who may find it useful.


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

Offline

Board footer

Powered by FluxBB