<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>langui.sh &#187; macvim bash</title>
	<atom:link href="http://langui.sh/tag/macvim-bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://langui.sh</link>
	<description>Fun hacks, WP plugins, photography, and PKI junk.  Languishing since 2008.</description>
	<lastBuildDate>Tue, 17 Jan 2012 20:23:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Improving mvim for MacVim</title>
		<link>http://langui.sh/2009/10/01/improving-mvim-for-macvim/</link>
		<comments>http://langui.sh/2009/10/01/improving-mvim-for-macvim/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 14:24:25 +0000</pubDate>
		<dc:creator>Paul Kehrer</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macvim bash]]></category>

		<guid isPermaLink="false">http://langui.sh/?p=671</guid>
		<description><![CDATA[<a href="http://langui.sh/2009/10/01/improving-mvim-for-macvim/" title="Improving mvim for MacVim"></a>MacVim comes with a clever script called mvim which allows you to open files in MacVim via the command line (much like mate for TextMate). This is a wonderful tool, but does possess some idiosyncrasies. It creates a new window &#8230;<p class="read-more"><a href="http://langui.sh/2009/10/01/improving-mvim-for-macvim/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://langui.sh/2009/10/01/improving-mvim-for-macvim/" title="Improving mvim for MacVim"></a><p><a href="http://code.google.com/p/macvim/">MacVim</a> comes with a clever script called <i>mvim</i> which allows you to open files in MacVim via the command line (much like <i>mate</i> for TextMate).  This is a wonderful tool, but does possess some idiosyncrasies.  It creates a new window (rather than a new tab) when you invoke it and it also won&#8217;t take stdin as input unless you pass a dash<sup class='footnote'><a href='#fn-671-1' id='fnref-671-1'>1</a></sup>.</p>
<p>To fix this I modified the script to check for an existing macvim process, and if it exists attach tabs to it.<sup class='footnote'><a href='#fn-671-2' id='fnref-671-2'>2</a></sup>  Additionally, it checks for args and if none are present (or just -) the script invokes stdin.  I am not much of a bash hacker though, so there are a few caveats&#8230;</p>
<ul>
<li>&#8211;remote-tab-silent doesn&#8217;t seem to work with listening on stdin, so the script always pops it out into a new window.</li>
<li>You (apparently) can&#8217;t pass extra parameters when using &#8211;remote-tab-silent, so tricks like mvim /etc/hosts +5 to have it open with the cursor on line 5 will not work.</li>
</ul>
<p>These are both irritating, but I feel the advantages outweigh the disadvantages.  Hopefully someone can contribute fixes to these problems!</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This shell script passes all its arguments to the binary inside the</span>
<span style="color: #666666; font-style: italic;"># MacVim.app application bundle.  If you make links to this script as view,</span>
<span style="color: #666666; font-style: italic;"># gvim, etc., then it will peek at the name used to call it and set options</span>
<span style="color: #666666; font-style: italic;"># appropriately.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Based on a script by Wout Mertens and suggestions from Laurent Bihanic.  This</span>
<span style="color: #666666; font-style: italic;"># version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico</span>
<span style="color: #666666; font-style: italic;"># Weber and Bjorn Winckler, Aug 13 2007.  Some mediocre hacking by Paul Kehrer Sep 30 2009).</span>
<span style="color: #666666; font-style: italic;"># First, check &quot;All the Usual Suspects&quot; for the location of the Vim.app bundle.</span>
<span style="color: #666666; font-style: italic;"># You can short-circuit this by setting the VIM_APP_DIR environment variable</span>
<span style="color: #666666; font-style: italic;"># or by un-commenting and editing the following line:</span>
<span style="color: #666666; font-style: italic;"># VIM_APP_DIR=/Applications</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VIM_APP_DIR</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">myDir</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`dirname &quot;$0&quot;`</span>&quot;</span>
	<span style="color: #007800;">myAppDir</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$myDir</span>/../Applications&quot;</span>
	<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> ~<span style="color: #000000; font-weight: bold;">/</span>Applications ~<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #007800;">$myDir</span> <span style="color: #007800;">$myDir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #007800;">$myAppDir</span> <span style="color: #007800;">$myAppDir</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>Applications <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>Utilities <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>Utilities<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">vim</span>; <span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-x</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>/MacVim.app&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
			<span style="color: #007800;">VIM_APP_DIR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span>
			<span style="color: #7a0874; font-weight: bold;">break</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VIM_APP_DIR</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Sorry, cannot find MacVim.app.  Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app.&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #007800;">binary</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$VIM_APP_DIR</span>/MacVim.app/Contents/MacOS/Vim&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Next, peek at the name used to invoke this script, and set options</span>
<span style="color: #666666; font-style: italic;"># accordingly.</span>
&nbsp;
<span style="color: #007800;">name</span>=<span style="color: #ff0000;">&quot;<span style="color: #780078;">`basename &quot;$0&quot;`</span>&quot;</span>
<span style="color: #007800;">gui</span>=
<span style="color: #007800;">opts</span>=
&nbsp;
<span style="color: #666666; font-style: italic;"># GUI mode, implies forking</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$name</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span> m<span style="color: #000000; font-weight: bold;">*|</span>g<span style="color: #000000; font-weight: bold;">*|</span>rg<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">gui</span>=<span style="color: #c20cb9; font-weight: bold;">true</span> <span style="color: #000000; font-weight: bold;">;;</span> <span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Restricted mode</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$name</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span> r<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">opts</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opts</span> -Z&quot;</span><span style="color: #000000; font-weight: bold;">;;</span> <span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># vimdiff and view</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$name</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
	<span style="color: #000000; font-weight: bold;">*</span>vimdiff<span style="color: #7a0874; font-weight: bold;">&#41;</span>
		<span style="color: #007800;">opts</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opts</span> -dO&quot;</span>
		<span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #000000; font-weight: bold;">*</span>view<span style="color: #7a0874; font-weight: bold;">&#41;</span>
		<span style="color: #007800;">opts</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$opts</span> -R&quot;</span>
		<span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #007800;">tabs</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #007800;">stdinoption</span>=<span style="color: #c20cb9; font-weight: bold;">false</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#let's see if we need to read from stdin</span>
<span style="color: #666666; font-style: italic;">#script currently assumes NO PARAMETERS</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$1</span> == \- <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">stdinoption</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Last step:  fire up vim.</span>
<span style="color: #666666; font-style: italic;"># The program should fork by default when started in GUI mode, but it does</span>
<span style="color: #666666; font-style: italic;"># not; we work around this when this script is invoked as &quot;gvim&quot; or &quot;rgview&quot;</span>
<span style="color: #666666; font-style: italic;"># etc., but not when it is invoked as &quot;vim -g&quot;.</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$gui</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #666666; font-style: italic;"># Note: this isn't perfect, because any error output goes to the</span>
	<span style="color: #666666; font-style: italic;"># terminal instead of the console log.</span>
	<span style="color: #666666; font-style: italic;"># But if you use open instead, you will need to fully qualify the</span>
	<span style="color: #666666; font-style: italic;"># path names for any filenames you specify, which is hard.</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #007800;">$stdinoption</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$binary</span>&quot;</span> <span style="color: #660033;">-g</span> - 
	<span style="color: #000000; font-weight: bold;">else</span> 
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #007800;">$tabs</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> x<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'MacOS/MacVim'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">grep</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">wc</span> -l<span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #007800;">$binary</span> --serverlist<span style="color: #000000; font-weight: bold;">`</span> = <span style="color: #ff0000;">&quot;VIM&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
			<span style="color: #666666; font-style: italic;">#when using remote tabs you can't pass things like +5.</span>
			<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$binary</span>&quot;</span> <span style="color: #660033;">-g</span> <span style="color: #007800;">$opts</span> <span style="color: #660033;">--remote-tab-silent</span> <span style="color: #800000;">${1:+&quot;$@&quot;}</span>
		<span style="color: #000000; font-weight: bold;">else</span>
			<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$binary</span>&quot;</span> <span style="color: #660033;">-g</span> <span style="color: #007800;">$opts</span> <span style="color: #800000;">${1:+&quot;$@&quot;}</span> 
		<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$binary</span>&quot;</span> <span style="color: #007800;">$opts</span> <span style="color: #800000;">${1:+&quot;$@&quot;}</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-671-1'>This is the standard vim way, but feels irritatingly inelegant to me. <span class='footnotereverse'><a href='#fnref-671-1'>&#8617;</a></span></li>
<li id='fn-671-2'>The script does a ps x to check for the existence of a macvim process.  This is done before the serverlist check because the script will output ugly errors to stdout if there is no macvim process. <span class='footnotereverse'><a href='#fnref-671-2'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://langui.sh/2009/10/01/improving-mvim-for-macvim/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached
Database Caching 4/16 queries in 0.004 seconds using memcached
Object Caching 396/419 objects using memcached

Served from: langui.sh @ 2012-02-07 06:42:27 -->
