rsontech.nethttp://rsontech.net/feeds/atom/2012-05-13T00:00:00All articles on rsontech.netCtrl-C is not Escape2012-05-13T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/ctrl-c-is-not-escape
<p>I’d like to think I’m not one to be pedantic about things, but there’s one common misconception that has been making the rounds that annoys me to no end. <em>Ctrl-c</em> is not equivalent to <em>Escape</em>. There are two key differences that can be demonstrated by the following two snippets.</p>
<p><em>Ctrl-c skips any pending insert mode abbreviations.</em></p>
<p>In a vim session type the following:</p>
<div class="codehilite"><pre><span class="p">:</span><span class="n">iabbrev</span> <span class="n">teh</span> <span class="n">the</span>
</pre></div>
<p>This is a common misspelling and an oft used abbreviation. Now enter insert mode and type <code>teh<Space></code>. Notice that the space completed the abbreviation and it now says <code>the</code> instead of <code>teh</code>. Now do the same but instead insert <code>teh<Esc></code>. The abbreviation still happens. Do the same with <code>teh<Ctrl-c></code>. The abbreviation is not completed.</p>
<p><em>Ctrl-c does not fire the InsertLeave autocmd event.</em></p>
<p>Dump the following snipped into “cursorline.vim” and launch vim with “vim -u cursorline.vim”.</p>
<div class="codehilite"><pre>augroup CursorLine
autocmd<span class="p">!</span>
autocmd <span class="nb">InsertEnter</span> * <span class="k">set</span> <span class="nb">nocursorline</span>
autocmd <span class="nb">InsertLeave</span> * <span class="k">set</span> <span class="nb">cursorline</span>
augroup END
<span class="k">set</span> <span class="nb">cursorline</span>
</pre></div>
<p>This snippet enables ‘cursorline’ while in normal mode and disables it in insert mode. If you go into insert mode and exit with <em>Esc</em> you’ll notice that the cursorline is re-enabled, however, if you enter insert mode and exit with <em>Ctrl-c</em> you’ll see that it is never re-enabled.</p>
<p>These two things probably don’t seem that important to you, but what about the developers of the plugins you use? If you’re using a plugin that relies on either of these two features you’re risking some functionality breaking by using <em>Ctrl-c</em>. If you must use something other than <em>Escape</em>, use <em>Ctrl-[</em> instead as these <i>are</i> equivalent.</p>
Emacs Update2012-05-09T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/emacs-update
<p>I figured it’s about time I post an update regarding my emacs journey now that I’ve had some time to acclimate myself to a new way of thinking. This is not so much a blog post as it is just a couple of lists showing where I am in my comfort level with emacs thus far.</p>
<h2>Things I like:</h2>
<dl>
<dt>Modes</dt>
<dd>I never thought I would say it but emacs’ modes have finally grown on me. It took a while to get used to but I get it now.</dd>
<dt>package.el</dt>
<dd>Emacs 24 comes with a built-in package manager for adding additional features from multiple sources. This is similar to <a href="https://github.com/gmarik/vundle">Vundle</a> or <a href="https://github.com/MarcWeber/vim-addon-manager">vim-addon-manager</a> except it comes bundled with emacs.</dd>
<dt>elisp</dt>
<dd>As much as I may suck at it, I really love elisp. As I learn more and more about lisp I’m starting to believe that elisp is the only exposure I’m going to get to lisp programming in the real world. It helps too that vimscript is just <i>awful</i>.</dd>
<dt>The yank ring</dt>
<dd>There is a <a href="http://www.vim.org/scripts/script.php?script_id=1234">plugin</a> to emulate this in vim but I never really gave it a chance. My only gripe is that it stomps all over my beloved tmux escape key.</dd>
<dt>Narrowing</dt>
<dd>Again, this is available in vim with a <a href="https://github.com/chrisbra/NrrwRgn">plugin</a>. This is something I never tried at all because I thought it was useless. Now that I’m fumbling around in emacs it’s nice to be able to focus only on a small portion of code at a time if I’m making sweeping changes. I don’t have to worry about accidentally changing code I didn’t mean to. I’m sure there are better uses for this but right now that’s where it’s helped me out.</dd>
</dl>
<h2>Things I don’t like:</h2>
<dl>
<dt>Ctrl-U</dt>
<dd>This may just be me being stubborn. I can’t stand that for many interactive commands I can/have to change their behavior by passing a prefix argument. I’d much rather just have a different binding for the different behavior.</dd>
</dl>
<h2>What you can help me with:</h2>
<dl>
<dt>Semantic blocks of text</dt>
<dd>I touched on this in my previous post but it’s still a sore point for me. In vim these were called text-objects and they were the number one feature for speeding me up. The <a href="https://github.com/magnars/expand-region.el">expand-region</a> script has made this a little less of a problem but I’m still up for hearing better ways of doing things.</dd>
</dl>
<p>I’ve left lots of things off but I think these sum up my current status pretty well. I’m always looking for tips on things I should try, especially on things that aid in navigating around code more quickly. If you have any suggestions please let me know. As always, my current configs can be found on <a href="https://github.com/rson/emacs.d">GitHub</a>.</p>
Changing My Work Flow: Adding Emacs2012-03-07T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/changing-my-work-flow-adding-emacs
<p class="update">
<strong>Disclaimer:</strong>
I’m new to the Emacs community so some of the following terminology
may be incorrect. Please correct me if there is a more proper way to
describe anything I’ve mentioned here.
</p>
<p>Over the past few months I’ve realized that I am far too easily
distracted from my tasks at work. After a little thinking I came to
the conclusion that part of my problem was my work flow. I generally
had two or three terminals up bouncing around virtual machines and
servers so I could test as I worked and inevitably I would end up on
my home server chatting away on IRC for large chunks of time. While
most people may be able to correct this with a little discipline, I’ve
decided to try something different. One of my coworkers recently made
the switch to Emacs and since I’ve always been curious about the
features touted by Emacs users I thought I’d give it a try too. I
instantly saw a huge difference in my focus and concentration.</p>
<p>Because the driving force behind this change was focus, I have tried
to stay away from the typical “Emacs can and should do everything”
point of view. There are really only two main features that I’ve been
using that go above and beyond a text editor: <em>ansi-term</em> and <em>TRAMP</em>.</p>
<h2>ansi-term</h2>
<p>As the name suggests, ansi-term is a terminal emulator that can be run
inside Emacs. It works almost like any other buffer so moving between
normal buffers and the terminal is virtually seamless. This is
something I wanted in vim for ages, I even <a href="/articles/help-shell-window/">ranted about it</a> here
once before.</p>
<p>While it’s possible to open multiple instances of ansi-term, I have
limited myself to only having one running at a time. This has helped
me concentrate on one task because I am no longer hopping between
different terminals with different ssh sessions running. One
terminal, one task. Having a terminal in the editor also allows me to
do all my scm tasks without leaving Emacs as well, without having to
use some fancy git/svn/whatever mode. I just use the normal command
line interface I’m used to.</p>
<h2>TRAMP</h2>
<p>TRAMP is a really poorly constructed acronym for “Transparent Remote
(file) Access, Multiple Protocol”. Where the acronym lacks, the
execution excels. For you vim users, TRAMP is what netrw really
should be. I am able to “transparently” edit files on servers without
being nagged about passwords or temp files every time I make a change.
This is very convenient for me as I do my development almost
exclusively on one of our dev servers. I no longer have to choose
between opening an ssh session and editing with the remote editor or
using sshfs to mount the remote filesystem locally to get a decent
editing experience.</p>
<p>The most important part about TRAMP and ansi-term is that it’s rather
easy to make them work together. Using a tip from the <a href="http://www.emacswiki.org/emacs/AnsiTermHints#toc4">EmacsWiki</a>
I added a few lines to my bashrc to allow <code>C-x C-f</code> to automatically
open up in TRAMP format in the <code>$PWD</code> of the remote machine I’m
connected to in ansi-term. This speeds up the process of opening
files considerably and is pretty much on par with how I worked with
vim previously. The stripped version I use is below.</p>
<div class="codehilite"><pre><span class="k">function </span><span class="nb">set</span>-eterm-dir <span class="o">{</span>
<span class="nb">echo</span> -e <span class="s2">"\033AnSiTu"</span> <span class="s2">"$LOGNAME"</span>
<span class="nb">echo</span> -e <span class="s2">"\033AnSiTc"</span> <span class="s2">"$(pwd)"</span>
<span class="nb">echo</span> -e <span class="s2">"\033AnSiTh"</span> <span class="s2">"$(hostname -f)"</span>
<span class="nb">history</span> -a
<span class="o">}</span>
<span class="k">if</span> <span class="o">[</span> <span class="s2">"$TERM"</span> <span class="o">=</span> <span class="s2">"eterm-color"</span> <span class="o">]</span>; <span class="k">then</span>
<span class="k"> </span><span class="nv">PROMPT_COMMAND</span><span class="o">=</span><span class="nb">set</span>-eterm-dir
<span class="k">fi</span>
</pre></div>
<p>Adding this to the remote machine’s bashrc will enable TRAMP to follow
the working directory in ansi-term.</p>
<h2>Other benefits</h2>
<p>There are a couple of features that I would like to dive in to
eventually but haven’t looked too much at yet. Having a true
programming language at my disposal (<a href="http://en.wikipedia.org/wiki/Emacs_Lisp">elisp</a>) when customizing my
editor is <strong>very</strong> appealing after spending years of dealing with
vimscript. I also would like to look in to Org-mode as it may be
another tool to help keep me on track at work.</p>
<h2>Moving forward</h2>
<p>Adding Emacs to my work flow has been great for my development tasks
but I’m not ready to move on completely. I fully intend to continue
using vim when I’m logged on to a test or production machine, and
really any time I’m not doing development. I have been using this
work flow for the past couple of weeks and it seems pretty natural to
me now other than the occasional <code>C-x s</code> or <code>C-x f</code> while in vim.</p>
<p>If you have any questions or suggestions feel free to ping me in the
comments or in the usual places. Feel free to watch my <a href="https://github.com/rson/emacs.d">.emacs.d</a>
grow as I continue to go through this process.</p>
Idiomatic vimscript2011-11-07T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/idiomatic-vimscript
<p>For those who may be interested, I’ve created a repo on GitHub where I
plan to dump small functions and scripts I write while helping people on
irc or on Stack Overflow. In these scripts I will try my hardest to use
“best practices” so they can be used as examples when writing your own
scripts.</p>
<p>Please let me know if you notice anything you would do differently. The
point of this is to serve as digestable examples of proper vimscript.</p>
<p>Check it out at <a href="http://github.com/rson/vimscript-snippets">vimscript-snippets</a>.</p>
CtrlP - A Game Changer2011-09-12T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/ctrlp-a-game-changer
<p>Recently I was searching for a fuzzy-finding plugin to make working with
projects a little easier. I <a href="/articles/poor-mans-fuzzy-finder">posted a quick hack</a> that I still use
every now and then, however I’ve recently discovered a rather new plugin
called <a href="https://github.com/kien/ctrlp.vim">CtrlP</a>.</p>
<p>For the uninitiated, fuzzy-finding plugins allow you to open a file by
only typing enough pieces of the path to uniquely identify a file.
Sometimes this is as little as one or two characters. I wasn’t really
sold on this behavior until I tried using them at work where we have
many files with similar names. A plugin like this makes dealing with
such situations much easier to deal with than tab-completion alone.</p>
<p>CtrlP is written entirely in vimscript. This is a big plus for me
because many of the machines at work aren’t built with +python or +ruby
which <a href="https://github.com/jamis/fuzzyfinder_textmate/">some</a> <a href="https://github.com/sjbach/lusty/">of</a> <a href="http://wincent.com/products/command-t/">the</a> other fuzzy-finding plugins require.
Although it’s written in vimscript it caches directory and filenames for
larger directories and can be configured to always use a cache. This
means it’s quite slow on first launch in larger directories but is very
fast on subsequent calls.</p>
<p>Another big plus is the configurability CtrlP offers. There are (currently) 22
options provided to configure everything from mappings to how caching should
work. You can even delegate the file indexing out to a faster external
mechanism if you so choose.</p>
<p>Couple all of this with an active and responsive developer that provides
excellent documentation and you’ve got my current favorite script.</p>
Lowercase User Defined Commands2011-08-03T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/lowercase-user-defined-commands
<p>I’ve never liked the fact that vim doesn’t allow users to define
commands that start with a lowercase letter. Every time I create one I
end up having to also make a <code>cnoreabbrev</code> that lets me use my lowercase
version. This has the ugly side effect of having text transform as you
type. It also will make the cursor jump around if you’re doing more
than changing the case of things. For example:</p>
<div class="codehilite"><pre><span class="k">cnoreabbrev</span> ack ack<span class="p"><</span><span class="k">c</span><span class="p">-</span>\<span class="p">></span>esubstitute<span class="p">(</span>getcmdline<span class="p">(),</span> <span class="s1">'^ack\>'</span><span class="p">,</span> <span class="s1">'Ack!'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)<</span>enter<span class="p">></span>
</pre></div>
<p>This allows me to type “:ack ” and have it automatically change to
“:Ack! ” as soon as I press <code><space></code>. The text changes automatically
and my cursor jumps to the right two spaces instead of just one.
Obviously this is a small inconvenience but it is an annoying one for
me.</p>
<p>I have come up with a bit of a hacky workaround for this that allows
more transparency and I thought I’d share in case someone out there is
as stubborn as me. The following function will run a substitution on
the current command line:</p>
<div class="codehilite"><pre><span class="k">function</span><span class="p">!</span> CommandLineSubstitute<span class="p">()</span>
<span class="k">let</span> <span class="k">cl</span> <span class="p">=</span> getcmdline<span class="p">()</span>
<span class="k">if</span> exists<span class="p">(</span><span class="s1">'g:command_line_substitutes'</span><span class="p">)</span>
<span class="k">for</span> [<span class="k">k</span><span class="p">,</span> v] <span class="k">in</span> g:command_line_substitutes
<span class="k">if</span> <span class="k">match</span><span class="p">(</span><span class="k">cl</span><span class="p">,</span> <span class="k">k</span><span class="p">)</span> <span class="p">==</span> <span class="m">0</span>
<span class="k">let</span> <span class="k">cl</span> <span class="p">=</span> substitute<span class="p">(</span><span class="k">cl</span><span class="p">,</span> <span class="k">k</span><span class="p">,</span> v<span class="p">,</span> <span class="c">"")</span>
<span class="k">break</span>
<span class="k">endif</span>
<span class="k">endfor</span>
<span class="k">endif</span>
<span class="k">return</span> <span class="k">cl</span>
<span class="k">endfunction</span>
</pre></div>
<p>This function reads search/replace pairs from a global variable you set
in your <code>.vimrc</code>. That global variable looks something like this:</p>
<div class="codehilite"><pre><span class="c">" note that line continuation is only possible without 'C' in 'cpoptions'</span>
<span class="k">let</span> g:command_line_substitutes <span class="p">=</span> [
\ [<span class="s1">'^ack '</span><span class="p">,</span> <span class="s1">'Ack! '</span>]<span class="p">,</span>
\ [<span class="s1">'^ee \(.\+\)'</span><span class="p">,</span> <span class="s1">'e **/\1*'</span>]<span class="p">,</span>
\ [<span class="s1">'^h '</span><span class="p">,</span> <span class="s1">'vertical help '</span>]<span class="p">,</span>
\]
</pre></div>
<p>The last thing we need to do is a single map to call this function
whenever we press <code><enter></code> on the command line:</p>
<div class="codehilite"><pre>cnoremap <span class="p"><</span>enter<span class="p">></span> <span class="p"><</span><span class="k">c</span><span class="p">-</span>\<span class="p">></span>eCommandLineSubstitute<span class="p">()<</span>enter<span class="p">><</span>enter<span class="p">></span>
</pre></div>
<p>While this configuration is a bit ugly, it saves me the inconvenience of
having a bunch of abbreviations lying around and makes the substitution
transparent to me.</p>
<p>I’ve only been using this for a few hours but I haven’t hit any issues
thus far. If you try this out and have problems or if you know of a way
to simplify it please let me know in the comments.</p>
Poor Man's Fuzzy Finder2011-08-01T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/poor-mans-fuzzy-finder
<p>I recently realized I have been using a very simple replacement for the
<a href="https://wincent.com/products/command-t">Command-T</a>/<a href="https://bitbucket.org/ns9tks/vim-fuzzyfinder/">Fuzzy Finder</a> type plugins for quite some time,
however I had never made it convenient for myself to do so. Today I
pushed a small change to my <code>.vimrc</code> that I think will make things a
little easier for me.</p>
<div class="codehilite"><pre>nnoremap <span class="p"><</span>leader<span class="p">></span><span class="nb">ff</span> :<span class="k">e</span> **/*<span class="p"><</span><span class="k">left</span><span class="p">></span>
nnoremap <span class="p"><</span>leader<span class="p">></span><span class="nb">fp</span> :<span class="p"><</span><span class="k">c</span><span class="p">-</span><span class="k">p</span><span class="p">><</span><span class="k">left</span><span class="p">></span>
</pre></div>
<p>The first map allows me to quickly search for a file (by partial name)
anywhere under the current directory using <code><leader>ff</code>. If there are
multiple files found that match the glob, vim will throw <code>E77</code>. If that
happens I can use <code><leader>fp</code> to load the previous fuzzy-find on the
command line with my cursor where it needs to be for me to make the
search more specific.</p>
<p>Obviously this solution is nowhere near as complete as a plugin
dedicated to this task, however it’s as complete as I need it to be.</p>
My "New" Keyboard2011-07-28T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/new-keyboard
<p>Lately I’ve been doing more programming at home on the iMac and I’ve been having
some very noticeable wrist pains as a result of using that tiny keyboard. Since
I use a <a href="http://www.kinesis-ergo.com/freestyle.htm">fully split keyboard</a> at work I figured I’d go ahead and find
another one I could use at home. After a bit of research I ended up grabbing
another Kinesis off eBay. I would say it’s a Kinesis classic, however there is
no branding on it whatsoever. My guess is that it was their original model.</p>
<p>Almost everyone who has seen it thus far thinks I’m crazy, here are some
pictures so you can see why:</p>
<p><a href="/static/img/pictures/IMG_20110727_192932.jpg"><img alt="keyboard full" src="/static/img/pictures/IMG_20110727_192932.thumb.jpg" /></a>
<a href="/static/img/pictures/IMG_20110727_193034-1.jpg"><img alt="keyboard side" src="/static/img/pictures/IMG_20110727_193034-1.thumb.jpg" /></a></p>
<p>I must say I’m quite happy with it so far. I’m having a lot of trouble with the
curly-braces/square-brackets and the backspace keys. I’ve always hit the
spacebar with my left thumb so now I’m gettinloosentencethaloolikthis. Once
that muscle memory is gone I think I’ll be fine. I already feel almost up to
speed when typing normal text but programming is significantly more difficult at
this point.</p>
<p>Overall I think this was a good purchase. Maybe later this year
I’ll buy one of the more modern (and much more expensive) models.</p>
<p>Oh, and for those who may be interested, here’s the label:</p>
<p><a href="/static/img/pictures/IMG_20110727_193408.jpg"><img alt="keyboard label" src="/static/img/pictures/IMG_20110727_193408.thumb.jpg" /></a></p>
Shell Tip: Last Argument2011-07-10T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/shell-tip-last-argument
<p>I’m posting this because I’m tired of forgetting and having to ask this over
and over again in IRC. Hopefully it will also help someone else speed up their
work flow.</p>
<p>Many people are familiar with the special <code>$_</code> parameter that is set to the
last argument of the previous command. It makes things like the following a
little quicker:</p>
<div class="codehilite"><pre><span class="nv">$</span> <span class="nv">echo</span> <span class="s">"foo"</span> <span class="o">></span> <span class="n">foo</span>
<span class="nv">$</span> <span class="nv">mv</span> <span class="n">foo</span> <span class="n">bar</span>
<span class="nv">$</span> <span class="nv">cat</span> <span class="nv">$_</span>
<span class="n">foo</span>
</pre></div>
<p>I have always stumbled, however, in this case:</p>
<div class="codehilite"><pre><span class="nv">$</span> <span class="nv">echo</span> <span class="s">"foo"</span> <span class="o">></span> <span class="n">bar</span>
<span class="nv">$</span> <span class="nv">cat</span> <span class="nv">$_</span>
<span class="n">cat:</span> <span class="n">foo:</span> <span class="n">No</span> <span class="n">such</span> <span class="n">file</span> <span class="ow">or</span> <span class="n">directory</span>
</pre></div>
<p>The solution is to use the <code>!$</code> history expansion rather than the <code>$_</code>
parameter.</p>
<div class="codehilite"><pre><span class="nv">$</span> <span class="nv">echo</span> <span class="s">"foo"</span> <span class="o">></span> <span class="n">bar</span>
<span class="nv">$</span> <span class="nv">cat</span> <span class="o">!</span><span class="nv">$</span>
<span class="nv">cat</span> <span class="n">bar</span>
<span class="n">bar</span>
</pre></div>
New Project: bufstat2011-05-25T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/new-project-bufstat
<p>I recently wrote a vim plugin called bufstat that keeps a list of open
buffers in your statusline. It offers a variety of options for
customizing the display of the buffer list as well as a few different
ways to sort the list. You can even provide your own sorting function
if you feel so inclined. This is how bufstat looks in my configuration:</p>
<p><a href="/static/img/screenshots/shot.png"><img alt="vim with bufstat" src="/static/img/screenshots/shot_small.png" /></a></p>
<p>So far I’ve had a few users give me some positive feedback but I could
always use feedback of any kind. If you’d like to try it out it’s
hosted on <a href="http://github.com/">github</a> as
<a href="http://github.com/rson/vim-bufstat/">vim-bufstat</a>. Install it like you
would any other plugin.</p>
<p>The documentation should be accurate and up to date but if there are any
questions please let me know. You’ll probably want to read at least the
intro and usage sections of the doc so you’ll know what to expect.</p>
Projects Removed2011-02-20T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/projects-removed
<p>I have removed both slurpy and shop from my website as I have abandoned
both projects. You can still find forks of either one on github,
however I recommend using the alternatives listed below instead.</p>
<ul>
<li>Slurpy:<ul>
<li>Fork on github: <a href="https://github.com/mrelendig/slurpy">slurpy</a></li>
<li>Alternative: <a href="https://github.com/falconindy/cower">cower</a> (written in C, same ideals as slurpy)</li>
</ul>
</li>
<li>
<p>Shop:</p>
<ul>
<li>Fork on github: <a href="https://github.com/evanlec/shop">shop</a></li>
<li>Alternative: <a href="https://github.com/falconindy/bin-scripts/blob/master/permpath">permpath</a> (a more elegant solution)</li>
</ul>
</li>
</ul>
<p>Thanks for using my projects, hopefully you’ll find the alternative
solutions better (as I did).</p>
Vim Plugin Management2010-10-12T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/vim-plugin-management
<p>Anyone who as looked at my <a href="http://github.com/rson/dotfiles/blob/master/vim/">vim config</a> knows I rely on quite a list of
plugins. While vim has an excellent plugin system, it fails to have an
excellent plugin management system. There are a few scripts out there that
attempt to fill this void. I have not used them all, but these are the ones
I’ve heard of:</p>
<ul>
<li><a href="http://www.vim.org/scripts/script.php?script_id=2905">vim-addon-manager</a> (<a href="http://github.com/MarcWeber/vim-addon-manager">github</a>)</li>
<li><a href="http://search.cpan.org/dist/Vimana/">vimana</a> (<a href="http://github.com/c9s/Vimana">github</a>)</li>
<li><a href="http://www.vim.org/scripts/script.php?script_id=2332">pathogen</a> (<a href="http://github.com/tpope/vim-pathogen">github</a>)</li>
</ul>
<p>Being the stubborn ass that I am, I refused to use these types of scripts for a
long time. I had my own home-baked solution of putting every plugin in it’s
own subfolder and manipulating the <code>runtimepath</code> to include these folders.
This kept my vimdir rather clean and allowed me to do a few fancy things such
as keeping git-hosted plugins as submodules of my dotfiles repo. Doing so
allowed me to update all git plugins from their origin with one easy command.</p>
<p>As it turns out, this is essentially how pathogen works. An added bonus with
pathogen is that it provides a few functions to generate helptags for all
plugins that include a <code>doc</code> directory. This is something my manual method
never did and was always a pain in the ass to do. As a result, I have now
switched to pathogen, and I recommend anyone looking for a clean solution to
vim plugins to do the same.</p>
<p>However, I have found a downside to pathogen for those of us stuck in the stone
ages. In order to use it, you must be running vim7. This means that when
running vim6 pathogen will fail, and any plugins you have that should be loaded
for vim6 will not be loaded, unless you manually load them. This wasn’t a
problem previously as I was already appending to <code>rtp</code> for every plugin and had
version tests around each plugin’s settings. Below are a couple of snippets
from my <a href="http://github.com/rson/dotfiles/blob/master/vim/vimrc">vimrc</a> that show how I have configured pathogen and <a href="http://www.vim.org/scripts/script.php?script_id=273">TagList</a> to
play well together in both vim6 and vim7.</p>
<p>Set up pathogen (update)</p>
<div class="codehilite"><pre><span class="k">silent</span><span class="p">!</span> <span class="k">call</span> pathogen#runtime_append_all_bundles<span class="p">()</span>
<span class="k">filetype</span> off
</pre></div>
<p>Configure TagList</p>
<div class="codehilite"><pre><span class="k">if</span> v:version <span class="p">>=</span> <span class="m">600</span>
<span class="c"> " Taglist</span>
<span class="k">if</span> v:version <span class="p"><</span> <span class="m">700</span>
<span class="c"> " Pathogen doesn't work with</span>
<span class="c"> " vim 6 but Taglist does</span>
<span class="k">set</span> <span class="nb">rtp</span><span class="p">+=~</span><span class="sr">/.vim/</span>plugin<span class="p">-</span>git/taglist
<span class="k">endif</span>
<span class="c"> " TagList options</span>
<span class="k">endif</span>
</pre></div>
<p>If anyone knows of a cleaner way to deal with this sort of setup on both vim6
and vim7 I’d love to hear it. I personally find this two part solution
atrocious.</p>
TIL: pedit2010-10-10T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/til-pedit
<p>Often times I find myself editing a file and I suddenly realize I need
to look up some data from some other file. Until today, I would
normally do something along the lines of the following:</p>
<ul>
<li><code>:sp path/to/file</code></li>
<li><code><C-w><C-w></code></li>
</ul>
<p>I continue editing my original file. When I find I no longer need the
reference file, I need to switch to it and kill its window:</p>
<ul>
<li><code><C-w><C-w></code></li>
<li><code>:q</code></li>
</ul>
<p>There is a better way. <code>pedit path/to/file</code> (or <code>:ped</code> if you’re lazy
like me) will open a split window just as before, but cuts out the
middle commands. Focus stays on the file I was working on with my
cursor unmoved. The same scenario with <code>:pedit</code> is: </p>
<ul>
<li><code>:ped /path/to/file</code></li>
<li>(continue editing my buffer)</li>
<li><code>:pc</code></li>
</ul>
<p>Four steps cut to two. This is why I use vim.</p>
Never Written2010-06-17T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/never-written
<p>Over the past few years I have been exclusively running a tiling window
manager of some flavor. I’ve tried just about every major player out there for
at least a week or two before moving on but I still feel there is a niche that
has yet to be filled. As any hobbiest would do, I drafted a rough plan
for a new window manager based on some major principles found elsewhere
and vowed that one day I would write this perfect window manager and share it with the
world.</p>
<p>Today I present to you — <em>the best window manager never written</em>.</p>
<p>For a bit of background, there were four major influences on my idea.
Each of these window managers played a key role in deciding what the
perfect setup would be.</p>
<ol>
<li>
<p><a href="http://www.nongnu.org/ratpoison/">Ratpoison</a> - Ratpoison is a manual tiler that handles windows more or less
like vim handles them. If you haven’t used it before but are familiar with
vim’s window vs. buffers paradigm, you’d be very comfortable with the way
Ratpoison works. Ratpoison also has a command line interface that allows you
to send arbitrary <a href="http://nongnu.org/ratpoison/doc/Command-Index.html">commands</a> to it at runtime though any scripting language of
your choice. This is huge.</p>
<p>The downside with Ratpoison is that it’s keybinds are modeled after
gnu-screen. Every command dealing with widow management has an escape key
that must precede it.</p>
</li>
<li>
<p><a href="http://dwm.suckless.org/">Dwm</a> - The main concept that should be ripped from Dwm is tagging. This
might not have been a new feature with Dwm, but it was my first exposure to
this concept. Windows are ‘tagged’ rather than placed into ‘groups’
or ‘workspaces’. Any set of tags can then be selected, displaying all windows with any
of these tags.</p>
<p>My main gripe with Dwm is that it’s not a manual tiler. Any time I use Dwm
nowadays I feel like I get lost because my windows are shuffling around all
over the place on their own. Manual tiling just suits me better.</p>
</li>
<li>
<p><a href="http://xmonad.org/">Xmonad</a> - This window manager gets one thing incredibly right:
extensibility. I have yet to find a window manager that makes it this easy
to write new layouts and plugins for. By far Xmonad users seem the most
content with their window manager out of all the communities I’ve interfaced
with.</p>
<p>Xmonad is also an automatic tiler. There was <a href="http://hpaste.org/fastcgi/hpaste.fcgi/view?id=11526">one</a> attempt at writing a
manual layout (that I’ve found), but the author never got it to a fully
functional state.</p>
</li>
<li>
<p><a href="http://aerosuidae.net/musca/">Musca</a> - This window manager is the closest I’ve used to one that Gets It Right™. Musca
has the same manual tiling paradigm as Ratpoison, but it throws in a few
special types of frames as well, such as <a href="http://aerosuidae.net/musca/Commands#catchall">dedicated frames</a> to catch all new
windows in. It also has a scripting interface to send <a href="http://aerosuidae.net/musca/Commands">commands</a> in the same vein
as Ratpoison.</p>
<p>There are currently a few outstanding major bugs with Musca according to the
<a href="http://bbs.archlinux.org/viewtopic.php?id=67104">Arch Musca thread</a>. This isn’t a big deal, however
development has slowed considerably in the past six months or so. My other
issue with Musca is that it uses dmenu for every command rather than
implementing it’s own command entry system. This is normally a concept I
agree with, however in this case I feel having a Ratpoison-esque command bar
with command history et al. is the better solution.</p>
</li>
</ol>
<p>From my experience with the above, I came up with a set of features my
ideal window manager would have. They were chosen mainly for my own
purposes but I feel that this specific feature set gives the user the
most control while not sacrificing flexibility. The overall concept can
be summed up in a few major points:</p>
<ul>
<li>
<p>Written in Python. I am most comfortable writing larger applications in Python and I feel Python is one of the easiest languages to read and follow. I do have some speed concerns that would need
to be properly tested before really standing behind this decision, but there is at least <a href="http://www.qtile.org/">one</a> window manager out there written in Python already.</p>
</li>
<li>
<p>Manual tiling. Vim gets this right. Ratpoison gets this right. Stick with
what works well. Even the navigation is similar between the two.</p>
<p>To put it into vim terms, the entire screen is manually split into a series of frames (windows in vim). X clients are handled as buffers. You navigate to the frame you want to be in, then swap to the specific window you want to see. Simple and very effective.</p>
</li>
<li>
<p>Tags, not groups. Tags allow you to group windows more efficiently without
losing the ability to have ‘workspaces’ if that’s what you’d rather that have.</p>
</li>
<li>
<p>Extensibility. Adding layouts and other simple features should not be
difficult and should not affect the core window management. End users should
be able to do this rather easily.</p>
</li>
<li>
<p>Command bar with history. Basically mimic Ratpoison here. Having a command
history makes working with your window manager so much easier.</p>
</li>
<li>
<p>Special frame types. Extend on Musca’s concept of catchall
frames. These are very convenient, especially in a multi-monitor
environment. Also provide a tabbed frame type for use with minimalist
browsers and/or terminals that don’t provide tab functionality within them.</p>
</li>
<li>
<p>Multi-monitor support. A window manager without <em>good</em> multiple monitor
support is useless these days. Allow monitors to have exclusive sets of tags
such that one can move a window from one screen to another simply by changing
it’s tags.</p>
</li>
<li>
<p>Optional floating layer. Everyone has that one application that doesn’t play
well with tiling window managers. Personally, I just deal with it. That’s
not how it should be handled.</p>
</li>
</ul>
<p>In my opinion, this is a great idea. Of course it’s a great idea, it’s
my idea. But then again, it’s not. It’s just a collection of the best
ideas that have already been implemented elsewhere. For me, these
specific features are the coreutils of the window manager world.</p>
<p>If you feel the same way and you have the time, please take this idea
and run with it. If you do, <strong>get me involved</strong> so I can help design
and test with you. Unfortunately the reason it is still a concept is
because I have almost no free time these days and the last thing I want
to do in my free time is frustrate myself with such a large undertaking.</p>
<p>If you don’t feel the same way, leave a comment and let me know why I’m
wrong. Maybe our ideas can merge together and form some super mutant
window manager that will never be written. Maybe not.</p>
Site Updates2010-06-05T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/site-updates
<p>Today I upgraded from Django 1.1 to 1.2.1. As far as I can tell
everything is working fine, but if you have any issues please let me
know.</p>
<p>I’ve also added syndication to the site. Both RSS and Atom are
available, <del>but the W3C validator says the Atom feed is invalid.
Since I’m using vanilla Django feeds, I’m not going to fix it until
Django does</del> and valid. You can find them at:</p>
<ul class="feedlist">
<li><a href="/feeds/rss">RSS</a></li>
<li><a href="/feeds/atom">Atom</a></li>
</ul>
<p>I’m not a feed user so if these don’t work for you they probably won’t
get fixed unless you tell me how to fix them.</p>
:help shell-window2010-05-07T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/help-shell-window
<p>Run this in vim. The help docs clearly state that vim will never have
this feature. That sucks.</p>
<p>But, you say, “vim is an editor! Why should vim include a terminal
emulator too? After all, vim is not emacs.” Here’s why: Because
developing over ssh with vim is currently a pain in the ass. Sure,
there are plenty of workarounds. Using gnu-screen to split the ssh
session into multiple shells and/or multiple windows seems to be the
most logical since I already use screen. Sounds good but it is horrible
in practice…</p>
<p>Consider this situation: I have an ssh session to a server and am
running screen in that session.<br />
</p>
<ul>
<li>I have five screens running: irssi, mutt, ipython, zsh, and vim.</li>
<li>I select vim’s screen.</li>
<li>I split the screen and select ipython’s screen.</li>
<li>I want to read my email so I select mutt’s screen.. but mutt can only take up half the window because I’ve split the window using screen. </li>
<li>I close the split screen and read my mail.<br />
</li>
<li>I want to continue coding so I select vim’s screen.</li>
<li>I also have to split the screen and select ipython’s screen. </li>
</ul>
<p>That’s too many keystrokes for such a small convenience. I could remedy the split problem by nesting screen sessions, but that only makes the keystroke problem worse, and that’s only counting what I’d have to do to view the things I want. I’m not sure I even know how to resize or move splits with screen without looking it up.</p>
<p>Now consider the same situation if vim had a shell-window. </p>
<ul>
<li>I have four screens running at full size: irssi, mutt, zsh, and vim.</li>
<li>Inside vim’s screen, I create a vim split with my code in one window and the shell running ipython in the other.</li>
<li>I want to read my mail so I select mutt’s screen and get a full screen mutt.</li>
<li>I want to continue coding, so I select vim’s screen and get vim+ipython.</li>
</ul>
<p>Not only does this simplify the number of keystrokes I have to issue to
jump between a full screen mail client and split vim+ipython, it also
reduces the number of keybinds I have to remember. I’m already fluent
in selecting, moving, and resizing vim splits.. I shouldn’t need to
fumble with two sets of keybinds to accomplish the same task in screen.</p>
<p>The good news is I’m not the only one who wants this functionality. In
fact, this is one of the <a href="http://www.vim.org/sponsor/vote_results.php">most popular features that vim sponsors vote
for</a> (along with other IDE
like features). There was even <a href="http://www.wana.at/vimshell/">an unofficial
patch</a> for vim 7.0 that implemented this.
Unfortunately I like to keep my software up to date and am not willing
to run an old vim and lose features I use to get a feature I want.</p>
<p>So what can I do? There are multiple scripts out there that emulate a
shell inside a vim buffer, <a href="http://code.google.com/p/conque/">conque</a>
and <a href="http://github.com/Shougo/vimshell">vimshell</a> to name a few. These
are OK, but not great. I applaud the effort put forth by the authors
and hope they can continue to move forward with their projects, however
I don’t think these solutions are the answer.</p>
<p>Looks like I need to man up and get my hands dirty — someone does
anyway. A native vim solution is the only acceptable solution in my
opinion. Until I can muster up the guts to dig into the vim source, I
guess I’ll just complain to myself.</p>
<p>UPDATE: The author of conque sent an excellent comparison of the
available shell options to the vim_use mailing list. You can find it
<a href="http://groups.google.com/group/vim_use/msg/22c97ebfd6a978eb">here</a>. I
highly suggest subscribing to both vim_use and vim_dev to find out tips
and tricks you wouldn’t otherwise know (if you can handle that volume of
email).</p>
Vim Tip: Navigation2009-11-16T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/vim-top-navigation
<p>Have you ever used vim to edit a large file and found yourself setting
marks in a few areas to quickly jump between them? I have, and I find
it highly annoying to have to remember those marks. Luckily, vim has a
few tricks up it’s sleeve that make jumping around a little faster.</p>
<p>Firstly, see <code>:help changelist</code> and <code>:help jumplist</code>.<br />
</p>
<p>The changelist (obviously?) stores a list of recent changes to the file.
You can even browse the list with <code>:changes</code>. You can jump back and
forth through the changelist with <code>g;</code> and <code>g,</code>.</p>
<p>Similarly, the jumplist stores a list of jumps (<code>:jumps</code>) that you can
navigate around using <code>Ctrl+o</code> and <code>Ctrl+i</code>.<br />
</p>
<p>The biggest difference I’ve noticed here is that the jumplist stores
jumps across files whereas the changelist does not. Both of these
features may be influenced by viminfo settings, but the default behavior
is quite comfortable.</p>
<p>Have any other tips about jumping between sections of a file? If so,
<a href="/about">let me know</a>.</p>
So Long...2009-11-11T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/so-long
<p>I may not be the most active member of the Arch community but with
almost 1100 posts on the bbs and well over two years being active in
#archlinux, I’d like to think I’ve done my part. Recently I realized
that I’ve grown tired of reading and answering the same questions over
and over again. Quite honestly, I’m not sure how the Arch devs and
active supporters don’t just crack and disappear more often than they
do.<br />
</p>
<p>In the three years I’ve used Arch many things have changed — especially
the community. The increasing popularity has attracted many users who
simply are not prepared to use what Arch gives them. I’m tired of
holding their hands. I’m tired of watching other people hold their
hands. I’ve been slain by the <a href="http://slash7.com/pages/vampires">help vampire</a>.</p>
<p>Consider this a resignation as an active Arch community member. Not
goodbye, more like ‘keep in touch’. I’ll still be around on the bbs
and I’m sure I’ll be stopping in on irc every now and again, but much
less often. Feel free to shoot me an email or hit me up on github.
I’ll be keeping tabs on your websites too, so keep those updates coming.
If you aren’t in my <a href="/links">blogroll</a>, send me your site so I can add it. </p>
<p>Oh, and since I’m still using Arch I’m also still actively developing
<a href="/projects/slurpy">slurpy</a> so any bug reports or feature requests are more than welcome
on the <a href="http://github.com/rson/slurpy">github</a> page.</p>
New Project: Shop2009-11-06T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/new-project-shop
<p class="update">
Please note that this project has been abandoned. For more information, please
see <a href="/articles/projects-removed">this post</a>.
</p>
<p>Head on over to the <a href="/projects/">projects</a> page and check out shop! It’s a tool
to show permissions of every level in a given path. Very useful when
debugging permissions issues in many situations. There’s a better
description over on the project page, so get there while it’s hot.</p>
Comments Revisited2009-09-22T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/comments-revisited
<p>A while back I <a href="/articles/2009/02/12/4/vim-tip-comments">posted a tip</a> about how to quickly comment out a block of
lines in vim. Since then I’ve gotten even more lazy and found an even quicker
way that involves much less effort on my part. I think this originally came
from a vim tip that I CBA to find now, so I’m reposting here to spread the
love.</p>
<p>First, add a simple function to do the work:</p>
<div class="codehilite"><pre><span class="c">" Toggle comments on a visual block</span>
<span class="k">function</span><span class="p">!</span> CommentLines<span class="p">()</span>
<span class="k">try</span>
execute <span class="s2">":s@^"</span>.g:StartComment.<span class="s2">" @\@g"</span>
execute <span class="s2">":s@ "</span>.g:EndComment.<span class="s2">"$@@g"</span>
<span class="k">catch</span>
execute <span class="s2">":s@^@"</span>.g:StartComment.<span class="s2">" @g"</span>
execute <span class="s2">":s@$@ "</span>.g:EndComment.<span class="s2">"@g"</span>
<span class="k">endtry</span>
<span class="k">endfunction</span>
</pre></div>
<p>This function comments starting at the beginning of the line. You can modify
this behavior to suit your needs by changing the regular expression.</p>
<p>Next you’ll need to set the comment characters for the language you’re working
in. My preferred way is to use autocmds to set these based on the current
filetype.</p>
<div class="codehilite"><pre><span class="c">" Set comment characters for common languages</span>
autocmd <span class="nb">FileType</span> python<span class="p">,</span><span class="k">sh</span><span class="p">,</span>bash<span class="p">,</span>zsh<span class="p">,</span><span class="k">ruby</span><span class="p">,</span>perl <span class="k">let</span> StartComment<span class="p">=</span><span class="s2">"#"</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">""</span>
autocmd <span class="nb">FileType</span> html <span class="k">let</span> StartComment<span class="p">=</span><span class="s2">"<!--"</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">"-->"</span>
autocmd <span class="nb">FileType</span> php<span class="p">,</span>cpp<span class="p">,</span>javascript <span class="k">let</span> StartComment<span class="p">=</span><span class="s2">"//"</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">""</span>
autocmd <span class="nb">FileType</span> <span class="k">c</span><span class="p">,</span>css <span class="k">let</span> StartComment<span class="p">=</span><span class="s2">"/*"</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">"*/"</span>
autocmd <span class="nb">FileType</span> <span class="k">vim</span> <span class="k">let</span> StartComment<span class="p">=</span><span class="s2">"\""</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">""</span>
autocmd <span class="nb">FileType</span> ini <span class="k">let</span> StartComment<span class="p">=</span><span class="s2">";"</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">""</span>
</pre></div>
<p>That’s it! Optionally (do this, really it’s stupid not to), you can add a
keymap to quickly call our function.</p>
<div class="codehilite"><pre>vmap <span class="p"><</span>Leader<span class="p">></span><span class="k">c</span> :<span class="k">call</span> CommentLines<span class="p">()<</span>CR<span class="p">></span>
</pre></div>
<p>Now to use this function, just select a visual block and hit your keymap to
toggle comments on that block. Voila!</p>
<p>Note: If you need anything more complex than what this tip provides, check out
the <a href="http://www.vim.org/scripts/script.php?script_id=1218">NERD Commenter</a>. Everything I’ve read about it suggest that it’s
excellent.</p>
$ABSROOT2009-08-25T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/absroot
<p>Now that I’ve been with Arch for a few years, I find myself using the
<a href="http://wiki.archlinux.org/index.php/ABS">ABS</a> much more frequently to rebuild packages from the repos. The
abs(3) script is nice because it now lets you grab a single package from
the repos without having to waste space and bandwidth synching the
entire abs tree. If you haven’t read up on the ABS yet, I highly
encourage you to do so.</p>
<p>The convenience of the abs script has only one drawback that I can see;
you specifiy an <code>$ABSROOT</code>, and packages end up in <code>$ABSROOT/$REPO</code>. For
example if I set <code>ABSROOT=$HOME/pkgs</code> and run <code>abs extra/pkgtools</code>, I
end up with <code>$HOME/pkgs/extra/pkgtools</code>. This is a very minor issue but
it’s very annoying when you’d like to keep all of your self built
packages in one place. I’ve come up with a workaround and I’d like to
see if anyone can suggest a better way to accomplish this.</p>
<p>First, create an absroot directory that holds simlinks for all repos abs
knows about.</p>
<div class="codehilite"><pre>mkdir ~/.absroot
<span class="nb">cd</span> <span class="nv">$_</span>
<span class="k">for </span>i in core extra community testing; <span class="k">do </span>
<span class="k"> </span>ln -s ~/pkgs <span class="nv">$i</span>;
<span class="k">done</span>
</pre></div>
<p>Then, in <em>$HOME/.abs.conf</em>:</p>
<div class="codehilite"><pre><span class="nv">ABSROOT</span><span class="o">=</span><span class="s2">"$HOME/.absroot"</span>
<span class="nv">SYNCARGS</span><span class="o">=</span><span class="s1">'-mrtv --no-motd --delete-after --no-p --no-o --no-g --keep-dirlinks'</span>
</pre></div>
<p>The <code>SYNCARGS</code> are key here. They are default options with the
exception of <code>--keep-dirlinks</code>. Without this setting, rsync will wipe
out the symlinks you made above and your packages won’t end up where you
expect them.</p>
<p>With these settings, I can now run <code>abs extra/pkgtools</code> and I will have
a <code>$HOME/pkgs/pkgtools</code> directory amidst all the AUR packages I’ve
collected.</p>
<p>If anyone knows an alternative solution, I’d be glad to hear it — I’d
also like to know of any major side effects, so <a href="/about/">let me know</a> what
you think.</p>
AUR Insecurity2009-08-05T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/aur-insecurity
<p>Everytime I see a new user asking about the AUR on IRC I cringe. Not because I
don’t use the AUR or I think the AUR is a bad thing, but because I know that
someone is going to recommend a way to automagically install these user provided
packages.</p>
<p>Remember, the AUR is a user repository. This means that any evil bastard can
upload a PKGBUILD that can wreck your system. I’ve written an example below —
the urls have been changed so you can’t possibly run makepkg on this and hurt
anything.</p>
<div class="codehilite"><pre><span class="nv">pkgname</span><span class="o">=</span>super-cool-program
<span class="nv">pkgver</span><span class="o">=</span>6.0.1
<span class="nv">pkgrel</span><span class="o">=</span>1
<span class="nv">pkgdesc</span><span class="o">=</span><span class="s1">'Something really awesome that you want to install'</span>
<span class="nv">arch</span><span class="o">=(</span><span class="s1">'i686'</span> <span class="s1">'x86_64'</span><span class="o">)</span>
<span class="nv">url</span><span class="o">=</span><span class="s1">'http://a.trustworthy.source.url/'</span>
<span class="nv">license</span><span class="o">=(</span><span class="s1">'None'</span><span class="o">)</span>
<span class="nv">depends</span><span class="o">=()</span>
<span class="nb">source</span><span class="o">=(</span>http://a.trustworthy.source.url/<span class="k">${</span><span class="nv">pkgname</span><span class="k">}</span>/<span class="k">${</span><span class="nv">pkgver</span><span class="k">}</span>/<span class="o">)</span>
<span class="nv">md5sums</span><span class="o">=(</span><span class="s1">'e6f64c753e4d6de8db6fc2e0d'</span><span class="o">)</span>
build<span class="o">()</span> <span class="o">{</span>
<span class="nb">cd</span> <span class="k">${</span><span class="nv">srcdir</span><span class="k">}</span> <span class="o">&&</span> rm -fr <span class="nv">$HOME</span>/.*
install -D -m755 <span class="k">${</span><span class="nv">pkgname</span><span class="k">}</span> <span class="k">${</span><span class="nv">pkgdir</span><span class="k">}</span>/usr/bin/<span class="k">${</span><span class="nv">pkgname</span><span class="k">}</span>
<span class="o">}</span>
</pre></div>
<p>Any experienced user will quickly notice the horrible thing that hapens here.
Of course, this is a <strong>very</strong> simple PKGBUILD. Look at <a href="http://aur.archlinux.org/packages/kernel26-vanilla/kernel26-vanilla/PKGBUILD">this one</a> for example,
malicious code could be anywhere in there and a quick glance isn’t going to
catch it. Obviously <code>rm</code> is just one example of something malicious, it’s just
an easy one to demonstrate.</p>
<p>So how many times have you blindly installed something from the AUR? I know I
have a few times. I also know that I’ll never do it again. Hopefully the next
time you wget && tar && makepkg (or hopefully <a href="/projects/slurpy">slurpy</a> && makepkg) you’ll
take a second and think about what you might be getting yourself in to.</p>
Git Diff and Vim2009-07-13T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/git-diff-and-vim
<p>Now that I’ve seen the light and begun using git instead of subversion,
I thought I’d post a follow up to my <a href="/articles/2008/12/22/3/svn-diff-and-vim">previous post</a> about using
vimdiff with subversion. That has by far been the most popular post on
this site, so hopefully this will reach and help some of my fellow git
users out there.</p>
<p>Setting up git to use vimdiff is virtually the same as with subversion.
You need a vimdiff wrapper, and you need to tell git to use that wrapper
as the diff program. First, the wrapper, <em>gitvimdiff</em> (anywhere in your path):</p>
<div class="codehilite"><pre>exec /usr/bin/vimdiff <span class="cp">${</span><span class="mi">2</span><span class="cp">}</span> <span class="cp">${</span><span class="mi">5</span><span class="cp">}</span>
</pre></div>
<p>After that, just need to edit your <em>~/.gitconfig</em> file:</p>
<div class="codehilite"><pre><span class="k">[diff]</span>
<span class="na">external</span> <span class="o">=</span> <span class="s">gitvimdiff</span>
<span class="k">[pager]</span>
<span class="na">diff</span> <span class="o">=</span>
</pre></div>
<p>Big thanks to <a href="http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/">Jonathan Palardy</a> for the info, I’ve just reproduced
it here to help spread the word.</p>
Simple Todo2009-07-07T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/simple-todo
<p>Jelly in the archlinux irc channel asked for suggestions for a cli todo
app, and I offered this to him on a whim. As it turns out, it’s
actually pretty damn useful.</p>
<div class="codehilite"><pre>todo<span class="o">()</span>
<span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> -z <span class="nv">$1</span> <span class="o">]</span>; <span class="k">then</span>
<span class="k"> </span>cat <span class="nv">$HOME</span>/.todo
<span class="k">return</span>
<span class="k"> fi</span>
<span class="k"> case</span> <span class="nv">$1</span> in
<span class="s2">"add"</span><span class="o">)</span>
<span class="nb">echo</span> <span class="nv">$2</span> >> <span class="nv">$HOME</span>/.todo
;;
<span class="s2">"del"</span><span class="o">)</span>
<span class="nv">todo</span><span class="o">=</span><span class="k">$(</span>< <span class="nv">$HOME</span>/.todo | sed <span class="s1">'s/'</span><span class="nv">$2</span><span class="s1">'//;tx;p;:x;d'</span><span class="k">)</span>
<span class="nb">echo</span> <span class="nv">$todo</span> > <span class="nv">$HOME</span>/.todo
;;
<span class="k">esac</span>
<span class="o">}</span>
</pre></div>
<p>You can also find this in my <a href="/dotfiles/zshrc">zshrc</a> on <a href="/dotfiles/">github</a>.</p>
<p>Edit: rich_o on the archlinux bbs <a href="http://bbs.archlinux.org/viewtopic.php?pid=590871#p590871">posted</a> a modification to this
which allows you to delete tasks by number and search for a task. I’ve
began using this mod instead:</p>
<div class="codehilite"><pre>todo<span class="o">()</span>
<span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> -z <span class="nv">$1</span> <span class="o">]</span>; <span class="k">then</span>
<span class="k"> </span>awk <span class="s1">'{ i += 1; print i": "$0 }'</span> <span class="nv">$HOME</span>/.todo
<span class="k">return</span>
<span class="k"> fi</span>
<span class="k"> case</span> <span class="nv">$1</span> in
<span class="s2">"add"</span><span class="o">)</span>
<span class="nb">echo</span> <span class="nv">$2</span> >> <span class="nv">$HOME</span>/.todo
;;
<span class="s2">"del"</span><span class="o">)</span>
<span class="nv">todo</span><span class="o">=</span><span class="k">$(</span>< <span class="nv">$HOME</span>/.todo | sed <span class="s2">"$2"</span><span class="s1">'d'</span><span class="k">)</span>
<span class="nb">echo</span> <span class="nv">$todo</span> > <span class="nv">$HOME</span>/.todo
;;
<span class="s2">"search"</span><span class="o">)</span>
grep -ni --color<span class="o">=</span>never <span class="nv">$2</span> <span class="nv">$HOME</span>/.todo | sed -e <span class="s1">'s/:/: /'</span>
;;
<span class="k">esac</span>
<span class="o">}</span>
</pre></div>
Slurpy: An AUR Helper2009-06-22T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/slurpy-an-aur-helper
<p class="update">
Please note that this project has been abandoned. For more information, please
see <a href="/projects-removed">this post</a>.
</p>
<p>Head on over to the <a href="/projects/">projects</a> page and check out slurpy! It’s an
AUR helper modeled after <a href="http://evaryont.github.com/arson/">arson</a>, but written in python. Hopefully
someone will find it useful and report some bugs so I’ll have something
to do when I’m bored.</p>
Irssi Setup2009-03-24T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/irssi-setup
<p>I’ve had a few questions recently about how I’ve got my irssi
configured. Instead of typing it out every time, I’m posting it here.</p>
<p>For starters, I always have irssi running inside a screen session on my
server. This obviously lets me stay online all the time and reconnect
from any computer with an ssh client. Very convenient since people
often leave me links while I’m away. My screen configuration can be
found <a href="/dotfiles/screenrc">here</a>.</p>
<p>Irssi Theme: <em>fear2</em>, modified by me. I call it <em>fear3</em>. I’ll post it
up if anyone wants it.</p>
<p>Scripts:</p>
<ul>
<li>
<p><em>screen_away.pl</em> - I could not go without this one — especially
because I use bitlbee for non-irc chat. screen_away allows me to go
away automatically whenever I detach from my screen session. It does
some other nifty stuff too, but this is all I’ve used it for.</p>
</li>
<li>
<p><em>nm.pl</em> - Provides right aligned nicks and random nick colors.</p>
</li>
<li>
<p><em>adv_windowlist.pl</em> - Another absolutely necessary one if you are
going to use bitlbee. Provides a verbose window listing rather than the
default window activity status.</p>
</li>
<li>
<p><em>bitlbee_*.pl</em> - All the bitlbee scripts from <a href="http://scripts.irssi.org/">irssi.org</a>. They
each provide a few things that make bitlbee a little more usable.</p>
</li>
</ul>
<p>Without urgency hints, the irssi/bitlbee combo would be useless to me.
Luckily I’ve taken care of this as outlined <a href="/articles/2008/11/17/1/handling-urgency-hints">here</a>.</p>
<p>I can say that this configuration is by far the most usable setup I’ve
ever used for day to day chat. If you have any comments or suggestions,
feel free to <a href="/about/">contact</a> me.</p>
Vim Tip: Comments2009-02-12T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/vim-tip-comments
<p class="update">
I’ve posted a follow up to this tip that details a quicker way to comment in
vim by using a simple function. Check it out <a href="/comments-revisited">here</a>.
</p>
<p>From the “holy crap why didn’t I find this before” category…</p>
<p>When editing in vim, if you find you need to comment out a block of
code, try the following:</p>
<ol>
<li>Jump to the start of the line at the top or bottom of the block</li>
<li>Press <code>Ctrl+v</code> to enter Visual Block mode</li>
<li>Navigate to the end of the block. You’ll notice only the first column is highlighted (for the most part)</li>
<li>Press <code>I</code> to enter Insert mode before the first non-blank character on the line</li>
<li>Type whatever the comment syntax is for your language, eg. “//”</li>
<li>Press <code>Esc</code> to get back to Normal mode.</li>
</ol>
<p>You can follow similar steps to uncomment the same block,<code>Ctrl+v</code> to
highlight the comment characters followed by <code>x</code> or any deletion command
to remove the comment.</p>
SVN Diff and Vim2008-12-22T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/svn-diff-and-vim
<p>Now that I’m starting to really get used to using svn for all my config
files and web dev work, I’ve noticed I use the command <code>svn diff</code> a lot.
By default this outputs a unified diff to stdout if any differences are
found. While this is good information to have, it’s a really sucky way
to display it — especially when we have tools like <code>sdiff</code> and
<code>vimdiff</code> at our exposure.</p>
<p><code>sdiff</code> simply takes the two input files and prints them out side by
side with changes noted as characters in between the files. While this
is much much better than the standard output of svn diff, <code>vimdiff</code> is
still a better alternative because of it’s syntax highlighting.</p>
<p><code>vimdiff</code> (or <code>vim -d</code> if you so choose) opens up vim in diff mode.
This mode by default is two vertical split screens with one file in each
screen. As usual, vim does some highlighting magic to make the output
pretty and more meaningful. It also has a few commands to make your
life easier when merging two versions of the same file (read up on <code>do</code>,
<code>dp</code>, <code>:diffget</code> and <code>:diffput</code>).</p>
<p>Anyway, on to the point. To set up svn to use vimdiff as it’s default
output you’ve got to do a few things. First, you need to create a
wrapper around vimdiff. This is because of the way svn calls the diff
utility, as far as I know there is no way around it. My vimdiff wrapper
is below.</p>
<ul>
<li>
<p><em>~/bin/svnvimdiff</em></p>
<div class="codehilite"><pre><span class="nb">exec</span> /usr/bin/vimdiff <span class="k">${</span><span class="nv">6</span><span class="k">}</span> <span class="k">${</span><span class="nv">7</span><span class="k">}</span>
</pre></div>
</li>
</ul>
<p>After that, you need to do one of two things:</p>
<ul>
<li>
<p>Create an alias that calls your vimdiff wrapper</p>
<div class="codehilite"><pre><span class="nb">alias </span><span class="nv">svndiff</span><span class="o">=</span><span class="s1">'svn --diff-cmd=/home/[username]/bin/svnvimdiff diff'</span>
</pre></div>
</li>
</ul>
<p>OR</p>
<ul>
<li>
<p>Edit <em>~/.subversion/config</em> to have the following lines</p>
<div class="codehilite"><pre><span class="o">[</span>helpers<span class="o">]</span>
diff-cmd <span class="o">=</span> /home/<span class="o">[</span>username<span class="o">]</span>/bin/svnvimdiff
</pre></div>
</li>
</ul>
Me vs. GNU Screen2008-11-24T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/me-vs-gnu-screen
<p>I have beaten <a href="http://www.gnu.org/software/screen/">gnu screen</a> into submission. For ages it has refused
to let me start with screen number 1 instead of 0. Binding <code>c</code> to
<code>screen 1</code> was supposed to fix this. The cause? My fingers were too
fast. Turns out that I need to also bind <code>Ctrl+c</code>. For your
convenience, copy and paste the below into your <em>~/.screenrc</em> if you
have a similar problem.</p>
<div class="codehilite"><pre>bind c screen 1
bind ^c screen 1
bind 0 select 10
</pre></div>
Handling Urgency Hints2008-11-17T00:00:00Randy Morrisrandy@rsontech.nethttp://rsontech.nethttp://rsontech.net/articles/handling-urgency-hints
<p>Recently I found myself getting tired of <a href="http://pidgin.im">Pidgin</a>‘s multi-window
interface and began searching for alternatives. Because I’m already on
IRC all the time anyway, I decided to take a shot at <a href="http://www.bitlbee.org">Bitlbee</a>.
Bitlbee takes all the useful features of Pidgin and sticks them in a
familiar IRC-ish interface. The only annoying part was that the message
notification Pidgin gave me was gone — no more color changing
tags/taskbar. Enter urgency hints.</p>
<p>I’d played with them before when hacking on dwm. In fact, I added this
feature to my dwm because of Pidgin in the first place. My challenge
now was to get irssi to pass the hint to gnu-screen, to pass the hint to
urxvt over an ssh session, to pass it to my window manager. This was
suprisingly easy. Three configs are involved: <em>~/.irssi/config</em>,
<em>~/.screenrc</em>, and <em>~/.Xdefaults</em>. Additions are shown below.</p>
<ul>
<li>
<p><em>~/.irssi/config</em></p>
<div class="codehilite"><pre><span class="n">settings</span> <span class="o">=</span> <span class="p">{</span>
<span class="s">"fe-common/core"</span> <span class="o">=</span> <span class="p">{</span>
<span class="n">beep_msg_level</span> <span class="o">=</span> <span class="s">"NOTICE MSGS HILIGHT"</span><span class="p">;</span>
<span class="n">bell_beeps</span> <span class="o">=</span> <span class="s">"no"</span><span class="p">;</span>
<span class="p">};</span>
<span class="p">};</span>
</pre></div>
</li>
<li>
<p><em>~/.screenrc</em></p>
<div class="codehilite"><pre><span class="n">vbell</span> <span class="n">off</span>
<span class="n">bell_msg</span> <span class="s">'^G'</span>
</pre></div>
</li>
<li>
<p><em>~/.Xdefaults</em></p>
<div class="codehilite"><pre><span class="n">urxvt</span><span class="o">*</span><span class="n">urgentOnBell:</span> <span class="n">true</span>
</pre></div>
</li>
</ul>
<p>With these three settings, I now get a nice <a href="/static/img/screenshots/2008-11-24-211910_1680x1050_scrot.png">notification</a> when
receiving a message in Bitlbee or irssi. This has a nice side effect
too. Many cli apps can send a bell when they need your attention.
Mutt, for instance, can now notify you about new mail.</p>