open urxvt here and open in vim applescript

  • April 26, 2009
Table of Contents

Update: noticed a little bug in the script, the right way to do it should be this:

set disp_no to do shell script "disp_no=($( ps -awx | grep -F 'bin/X' | awk '{print $(NF-2)}' | grep -e \":[0-9]\"  )); if [[ -n $disp_no ]];then DISPLAY=${disp_no}.0; else DISPLAY=:0.0; fi;echo $DISPLAY"

if you have tcp forward off, maybe without $NF if it’s enabled but anyway grep -F X11.app won’t work with newer X versions

If you don’t already know I use x11 and a selfcompiled terminal version of vim for all my work. If you’re in OS-X you might still want to run text files in your favorite editor, and have the ability to open the terminal in the current finder version for whatever reason.

I started using Fastscripts Light a long time ago and it’s a pretty nifty little app. The applescript is based a bit on the OpenInTerminal applescript.

However, for some reason when I run the scripts from Fastscripts via hotkey the DISPLAY variable is wrong as follows:

/tmp/launch-9el5tK/:0

I use the following in my shell config files(sorry, it’s not really mine, but I have no idea who I got it from)

# Set the DISPLAY variable -- works for Apple X11 with Fast User Switching

if [[ -z $DISPLAY && -z $SSH_CONNECTION ]]; then
    disp_no=($( ps -awx | grep -F X11.app | awk '{print $NF}' | grep -e ":[0-9]"  ))
    if [[ -n $disp_no ]];then
        export DISPLAY=${disp_no}.0
    else
        export DISPLAY=:0.0
    fi
    echo "DISPLAY has been set to $DISPLAY"
fi

Anyway, the to fix the openinrxvt all you need to do is change it the following way:

disp_no=($( ps -awx | grep -F X11.app | awk '{print $NF}' | grep -e ":[0-9]"  ))
if [[ -n $disp_no ]];then
    DISPLAY=${disp_no}.0
else
    DISPLAY=:0.0
fi
echo $DISPLAY

compressed, the Applescript looks as follows:

set disp_no to do shell script "disp_no=($( ps -awx | grep -F X11.app | awk '{print $NF}' | grep -e \":[0-9]\"  )); if [[ -n $disp_no ]];then DISPLAY=${disp_no}.0; else DISPLAY=:0.0; fi;echo $DISPLAY"

do shell script "env DISPLAY=" & disp_no & " /opt/local/bin/urxvt -cd '" & the_path & "' &> /dev/null &"
tell application "X11" to activate

Running vim is pretty much the same except that you will need to compile a console version with the server option, and then run the original instance with –servername VIM (or whatever servername you might want to use).

The relevant launch part of the Applescript looks like this:

do shell script "env DISPLAY=" & disp_no & " /opt/local/vim/bin/vim --remote \"" & the_path & "\" &> /dev/null &"

You can get the complete openinrxvt script here and the run in vim script here

After you place them into your ~/Library/Scripts/Applications/Finder folder you can use Fastscripts:fastscripts to create Finder specific hotkeys.

You might also be interested in a modified version of the script that uses the client/daemon set up of urxvt, which I talked about earlier.

do shell script "env RXVT_SOCKET=$HOME/.rxvt_socket DISPLAY=" & disp_no & " /opt/local/bin/urxvtc -cd '" & the_path & "' &> /dev/null &"
comments powered by Disqus

Related Posts

ruby-enterprise/ruby-1.8.7 in fedora 15 or archlinux

The following bugs occur when trying to install ruby enterprise on distros like fedora 15 or archlinux:

Read More

Precompiled qgit.app 2.2 for Mac

So I was looking for a git visualizer the other day… GitNub looks nifty but doesn’t quite cut it and gitk is just plain ugly.

Read More

Better tab completion for scp file names

As a lot of you may know, zsh offers tab completion for scp: filenames.
Normally it would connect and then list the files. As you can imagine this isn’t really that efficient.
The solution is quite simple… By adding

Read More