Question

Preface: I'm writing a tmuxinator clone based for i3, and I'm a zsh user.

I want to open a xterm window (or any other terminal) in a given directory, where a .rvmrc file is present, and launch a (ruby-related) command.

Here an example scenario:

➜  /tmp  irb
2.0.0p0 :001 > 
➜  /tmp  cat r/.rvmrc 
rvm --create use 1.9.3@cloudflo-cfu
➜  /tmp  cd r  
Using /home/user/.rvm/gems/ruby-1.9.3-p392 with gemset cloudflo-cfu
➜  r  irb
1.9.3p392 :001 >

As you can see I'm using 2.0.0 as system ruby, and 1.9.3 in the r/ direcotry. I want, from some other place, launch an xterm window in that directory run irb and keep the terminal after that.

From a console I can do:

➜  /tmp  (cd /tmp/r && xterm -e "irb ; $SHELL ")&

This will work but the rvm load is done from the current terminal, and this trick cannot be done from a script:

➜  /tmp  cat test/start1.sh 
 (cd /tmp/r && xterm -e "irb ; $SHELL ")&
➜  /tmp  ./test/start1.sh

This will open irb in the 2.0.0 version.

So, how do I achieve this?

More in detail, what I'm trying to do is to spot the correct command message for i3-msg utility (that I'm using via i3-py binding uwing i3.exec().

The result should do the following things:

  • Start a terminal (xterm preferably)
  • go to a given directory having rvm function loaded (or a workaround for the cd wrapper function of rvm)
  • launch a command (irb is fine for testing)
  • launch $SHELL to prevent the terminal to be closed once exiting from irb
Was it helpful?

Solution

this command should do it:

( cd /tmp/r ; xterm -e $SHELL -l -c "irb ; $SHELL" )&

it will change to the directory, start xterm with running login(-l) shell($SHELL) in it and asking it to execute(-c) irb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top