rsontech.net http://rsontech.net/feeds/rss/ All articles on rsontech.net en-us Sun, 13 May 2012 00:00:00 Ctrl-C is not Escape http://rsontech.net/articles/ctrl-c-is-not-escape <p>I&#8217;d like to think I&#8217;m not one to be pedantic about things, but there&#8217;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&lt;Space&gt;</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&lt;Esc&gt;</code>. The abbreviation still happens. Do the same with <code>teh&lt;Ctrl-c&gt;</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 &#8220;cursorline.vim&#8221; and launch vim with &#8220;vim -u cursorline.vim&#8221;.</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 &#8216;cursorline&#8217; while in normal mode and disables it in insert mode. If you go into insert mode and exit with <em>Esc</em> you&#8217;ll notice that the cursorline is re-enabled, however, if you enter insert mode and exit with <em>Ctrl-c</em> you&#8217;ll see that it is never re-enabled.</p> <p>These two things probably don&#8217;t seem that important to you, but what about the developers of the plugins you use? If you&#8217;re using a plugin that relies on either of these two features you&#8217;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> randy@rsontech.net (Randy Morris) Sun, 13 May 2012 00:00:00 http://rsontech.net/articles/ctrl-c-is-not-escape Emacs Update http://rsontech.net/articles/emacs-update <p>I figured it&#8217;s about time I post an update regarding my emacs journey now that I&#8217;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&#8217; 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&#8217;m starting to believe that elisp is the only exposure I&#8217;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&#8217;m fumbling around in emacs it&#8217;s nice to be able to focus only on a small portion of code at a time if I&#8217;m making sweeping changes. I don&#8217;t have to worry about accidentally changing code I didn&#8217;t mean to. I&#8217;m sure there are better uses for this but right now that&#8217;s where it&#8217;s helped me out.</dd> </dl> <h2>Things I don&#8217;t like:</h2> <dl> <dt>Ctrl-U</dt> <dd>This may just be me being stubborn. I can&#8217;t stand that for many interactive commands I can/have to change their behavior by passing a prefix argument. I&#8217;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&#8217;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&#8217;m still up for hearing better ways of doing things.</dd> </dl> <p>I&#8217;ve left lots of things off but I think these sum up my current status pretty well. I&#8217;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> randy@rsontech.net (Randy Morris) Wed, 09 May 2012 00:00:00 http://rsontech.net/articles/emacs-update Changing My Work Flow: Adding Emacs http://rsontech.net/articles/changing-my-work-flow-adding-emacs <p class="update"> <strong>Disclaimer:</strong> I&#8217;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&#8217;ve mentioned here. </p> <p>Over the past few months I&#8217;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&#8217;ve decided to try something different. One of my coworkers recently made the switch to Emacs and since I&#8217;ve always been curious about the features touted by Emacs users I thought I&#8217;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 &#8220;Emacs can and should do everything&#8221; point of view. There are really only two main features that I&#8217;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&#8217;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&#8217;m used to.</p> <h2>TRAMP</h2> <p>TRAMP is a really poorly constructed acronym for &#8220;Transparent Remote (file) Access, Multiple Protocol&#8221;. Where the acronym lacks, the execution excels. For you vim users, TRAMP is what netrw really should be. I am able to &#8220;transparently&#8221; 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&#8217;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&#8217;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">&quot;\033AnSiTu&quot;</span> <span class="s2">&quot;$LOGNAME&quot;</span> <span class="nb">echo</span> -e <span class="s2">&quot;\033AnSiTc&quot;</span> <span class="s2">&quot;$(pwd)&quot;</span> <span class="nb">echo</span> -e <span class="s2">&quot;\033AnSiTh&quot;</span> <span class="s2">&quot;$(hostname -f)&quot;</span> <span class="nb">history</span> -a <span class="o">}</span> <span class="k">if</span> <span class="o">[</span> <span class="s2">&quot;$TERM&quot;</span> <span class="o">=</span> <span class="s2">&quot;eterm-color&quot;</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&#8217;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&#8217;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&#8217;m not ready to move on completely. I fully intend to continue using vim when I&#8217;m logged on to a test or production machine, and really any time I&#8217;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> randy@rsontech.net (Randy Morris) Wed, 07 Mar 2012 00:00:00 http://rsontech.net/articles/changing-my-work-flow-adding-emacs Idiomatic vimscript http://rsontech.net/articles/idiomatic-vimscript <p>For those who may be interested, I&#8217;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 &#8220;best practices&#8221; 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> randy@rsontech.net (Randy Morris) Mon, 07 Nov 2011 00:00:00 http://rsontech.net/articles/idiomatic-vimscript CtrlP - A Game Changer http://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&#8217;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&#8217;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&#8217;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&#8217;s written in vimscript it caches directory and filenames for larger directories and can be configured to always use a cache. This means it&#8217;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&#8217;ve got my current favorite script.</p> randy@rsontech.net (Randy Morris) Mon, 12 Sep 2011 00:00:00 http://rsontech.net/articles/ctrlp-a-game-changer Lowercase User Defined Commands http://rsontech.net/articles/lowercase-user-defined-commands <p>I&#8217;ve never liked the fact that vim doesn&#8217;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&#8217;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">&lt;</span><span class="k">c</span><span class="p">-</span>\<span class="p">&gt;</span>esubstitute<span class="p">(</span>getcmdline<span class="p">(),</span> <span class="s1">&#39;^ack\&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;Ack!&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)&lt;</span>enter<span class="p">&gt;</span> </pre></div> <p>This allows me to type &#8220;:ack &#8221; and have it automatically change to &#8220;:Ack! &#8221; as soon as I press <code>&lt;space&gt;</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&#8217;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">&#39;g:command_line_substitutes&#39;</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">&quot;&quot;)</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">&quot; note that line continuation is only possible without &#39;C&#39; in &#39;cpoptions&#39;</span> <span class="k">let</span> g:command_line_substitutes <span class="p">=</span> [ \ [<span class="s1">&#39;^ack &#39;</span><span class="p">,</span> <span class="s1">&#39;Ack! &#39;</span>]<span class="p">,</span> \ [<span class="s1">&#39;^ee \(.\+\)&#39;</span><span class="p">,</span> <span class="s1">&#39;e **/\1*&#39;</span>]<span class="p">,</span> \ [<span class="s1">&#39;^h &#39;</span><span class="p">,</span> <span class="s1">&#39;vertical help &#39;</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>&lt;enter&gt;</code> on the command line:</p> <div class="codehilite"><pre>cnoremap <span class="p">&lt;</span>enter<span class="p">&gt;</span> <span class="p">&lt;</span><span class="k">c</span><span class="p">-</span>\<span class="p">&gt;</span>eCommandLineSubstitute<span class="p">()&lt;</span>enter<span class="p">&gt;&lt;</span>enter<span class="p">&gt;</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&#8217;ve only been using this for a few hours but I haven&#8217;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> randy@rsontech.net (Randy Morris) Wed, 03 Aug 2011 00:00:00 http://rsontech.net/articles/lowercase-user-defined-commands Poor Man's Fuzzy Finder http://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">&lt;</span>leader<span class="p">&gt;</span><span class="nb">ff</span> :<span class="k">e</span> **/*<span class="p">&lt;</span><span class="k">left</span><span class="p">&gt;</span> nnoremap <span class="p">&lt;</span>leader<span class="p">&gt;</span><span class="nb">fp</span> :<span class="p">&lt;</span><span class="k">c</span><span class="p">-</span><span class="k">p</span><span class="p">&gt;&lt;</span><span class="k">left</span><span class="p">&gt;</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>&lt;leader&gt;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>&lt;leader&gt;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&#8217;s as complete as I need it to be.</p> randy@rsontech.net (Randy Morris) Mon, 01 Aug 2011 00:00:00 http://rsontech.net/articles/poor-mans-fuzzy-finder My "New" Keyboard http://rsontech.net/articles/new-keyboard <p>Lately I&#8217;ve been doing more programming at home on the iMac and I&#8217;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&#8217;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&#8217;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&#8217;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&#8217;m quite happy with it so far. I&#8217;m having a lot of trouble with the curly-braces/square-brackets and the backspace keys. I&#8217;ve always hit the spacebar with my left thumb so now I&#8217;m gettinloosentencethaloolikthis. Once that muscle memory is gone I think I&#8217;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&#8217;ll buy one of the more modern (and much more expensive) models.</p> <p>Oh, and for those who may be interested, here&#8217;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> randy@rsontech.net (Randy Morris) Thu, 28 Jul 2011 00:00:00 http://rsontech.net/articles/new-keyboard Shell Tip: Last Argument http://rsontech.net/articles/shell-tip-last-argument <p>I&#8217;m posting this because I&#8217;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">&quot;foo&quot;</span> <span class="o">&gt;</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">&quot;foo&quot;</span> <span class="o">&gt;</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">&quot;foo&quot;</span> <span class="o">&gt;</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> randy@rsontech.net (Randy Morris) Sun, 10 Jul 2011 00:00:00 http://rsontech.net/articles/shell-tip-last-argument New Project: bufstat http://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&#8217;ve had a few users give me some positive feedback but I could always use feedback of any kind. If you&#8217;d like to try it out it&#8217;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&#8217;ll probably want to read at least the intro and usage sections of the doc so you&#8217;ll know what to expect.</p> randy@rsontech.net (Randy Morris) Wed, 25 May 2011 00:00:00 http://rsontech.net/articles/new-project-bufstat Projects Removed http://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&#8217;ll find the alternative solutions better (as I did).</p> randy@rsontech.net (Randy Morris) Sun, 20 Feb 2011 00:00:00 http://rsontech.net/articles/projects-removed Vim Plugin Management http://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&#8217;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&#8217;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&#8217;t a problem previously as I was already appending to <code>rtp</code> for every plugin and had version tests around each plugin&#8217;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">&gt;=</span> <span class="m">600</span> <span class="c"> &quot; Taglist</span> <span class="k">if</span> v:version <span class="p">&lt;</span> <span class="m">700</span> <span class="c"> &quot; Pathogen doesn&#39;t work with</span> <span class="c"> &quot; 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"> &quot; 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&#8217;d love to hear it. I personally find this two part solution atrocious.</p> randy@rsontech.net (Randy Morris) Tue, 12 Oct 2010 00:00:00 http://rsontech.net/articles/vim-plugin-management TIL: pedit http://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>&lt;C-w&gt;&lt;C-w&gt;</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>&lt;C-w&gt;&lt;C-w&gt;</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&#8217;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> randy@rsontech.net (Randy Morris) Sun, 10 Oct 2010 00:00:00 http://rsontech.net/articles/til-pedit Never Written http://rsontech.net/articles/never-written <p>Over the past few years I have been exclusively running a tiling window manager of some flavor. I&#8217;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 &#8212; <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&#8217;t used it before but are familiar with vim&#8217;s window vs. buffers paradigm, you&#8217;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&#8217;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 &#8216;tagged&#8217; rather than placed into &#8216;groups&#8217; or &#8216;workspaces&#8217;. 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&#8217;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&#8217;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&#8217;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&#8217;ve used to one that Gets It Right&#0153;. 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&#8217;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&#8217;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 &#8216;workspaces&#8217; if that&#8217;s what you&#8217;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&#8217;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&#8217;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&#8217;s tags.</p> </li> <li> <p>Optional floating layer. Everyone has that one application that doesn&#8217;t play well with tiling window managers. Personally, I just deal with it. That&#8217;s not how it should be handled.</p> </li> </ul> <p>In my opinion, this is a great idea. Of course it&#8217;s a great idea, it&#8217;s my idea. But then again, it&#8217;s not. It&#8217;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&#8217;t feel the same way, leave a comment and let me know why I&#8217;m wrong. Maybe our ideas can merge together and form some super mutant window manager that will never be written. Maybe not.</p> randy@rsontech.net (Randy Morris) Thu, 17 Jun 2010 00:00:00 http://rsontech.net/articles/never-written Site Updates http://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&#8217;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&#8217;m using vanilla Django feeds, I&#8217;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&#8217;m not a feed user so if these don&#8217;t work for you they probably won&#8217;t get fixed unless you tell me how to fix them.</p> randy@rsontech.net (Randy Morris) Sat, 05 Jun 2010 00:00:00 http://rsontech.net/articles/site-updates :help shell-window http://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, &#8220;vim is an editor! Why should vim include a terminal emulator too? After all, vim is not emacs.&#8221; Here&#8217;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&#8230;</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&#8217;s screen.</li> <li>I split the screen and select ipython&#8217;s screen.</li> <li>I want to read my email so I select mutt&#8217;s screen.. but mutt can only take up half the window because I&#8217;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&#8217;s screen.</li> <li>I also have to split the screen and select ipython&#8217;s screen. </li> </ul> <p>That&#8217;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&#8217;s only counting what I&#8217;d have to do to view the things I want. I&#8217;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&#8217;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&#8217;s screen and get a full screen mutt.</li> <li>I want to continue coding, so I select vim&#8217;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&#8217;m already fluent in selecting, moving, and resizing vim splits.. I shouldn&#8217;t need to fumble with two sets of keybinds to accomplish the same task in screen.</p> <p>The good news is I&#8217;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&#8217;t think these solutions are the answer.</p> <p>Looks like I need to man up and get my hands dirty &#8212; 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&#8217;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&#8217;t otherwise know (if you can handle that volume of email).</p> randy@rsontech.net (Randy Morris) Fri, 07 May 2010 00:00:00 http://rsontech.net/articles/help-shell-window Vim Tip: Navigation http://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&#8217;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&#8217;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> randy@rsontech.net (Randy Morris) Mon, 16 Nov 2009 00:00:00 http://rsontech.net/articles/vim-top-navigation So Long... http://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&#8217;d like to think I&#8217;ve done my part. Recently I realized that I&#8217;ve grown tired of reading and answering the same questions over and over again. Quite honestly, I&#8217;m not sure how the Arch devs and active supporters don&#8217;t just crack and disappear more often than they do.<br /> </p> <p>In the three years I&#8217;ve used Arch many things have changed &#8212; especially the community. The increasing popularity has attracted many users who simply are not prepared to use what Arch gives them. I&#8217;m tired of holding their hands. I&#8217;m tired of watching other people hold their hands. I&#8217;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 &#8216;keep in touch&#8217;. I&#8217;ll still be around on the bbs and I&#8217;m sure I&#8217;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&#8217;ll be keeping tabs on your websites too, so keep those updates coming. If you aren&#8217;t in my <a href="/links">blogroll</a>, send me your site so I can add it. </p> <p>Oh, and since I&#8217;m still using Arch I&#8217;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> randy@rsontech.net (Randy Morris) Wed, 11 Nov 2009 00:00:00 http://rsontech.net/articles/so-long New Project: Shop http://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&#8217;s a tool to show permissions of every level in a given path. Very useful when debugging permissions issues in many situations. There&#8217;s a better description over on the project page, so get there while it&#8217;s hot.</p> randy@rsontech.net (Randy Morris) Fri, 06 Nov 2009 00:00:00 http://rsontech.net/articles/new-project-shop Comments Revisited http://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&#8217;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&#8217;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">&quot; 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">&quot;:s@^&quot;</span>.g:StartComment.<span class="s2">&quot; @\@g&quot;</span> execute <span class="s2">&quot;:s@ &quot;</span>.g:EndComment.<span class="s2">&quot;$@@g&quot;</span> <span class="k">catch</span> execute <span class="s2">&quot;:s@^@&quot;</span>.g:StartComment.<span class="s2">&quot; @g&quot;</span> execute <span class="s2">&quot;:s@$@ &quot;</span>.g:EndComment.<span class="s2">&quot;@g&quot;</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&#8217;ll need to set the comment characters for the language you&#8217;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">&quot; 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">&quot;#&quot;</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">&quot;&quot;</span> autocmd <span class="nb">FileType</span> html <span class="k">let</span> StartComment<span class="p">=</span><span class="s2">&quot;&lt;!--&quot;</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">&quot;--&gt;&quot;</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">&quot;//&quot;</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">&quot;&quot;</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">&quot;/*&quot;</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">&quot;*/&quot;</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">&quot;\&quot;&quot;</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">&quot;&quot;</span> autocmd <span class="nb">FileType</span> ini <span class="k">let</span> StartComment<span class="p">=</span><span class="s2">&quot;;&quot;</span> <span class="p">|</span> <span class="k">let</span> EndComment<span class="p">=</span><span class="s2">&quot;&quot;</span> </pre></div> <p>That&#8217;s it! Optionally (do this, really it&#8217;s stupid not to), you can add a keymap to quickly call our function.</p> <div class="codehilite"><pre>vmap <span class="p">&lt;</span>Leader<span class="p">&gt;</span><span class="k">c</span> :<span class="k">call</span> CommentLines<span class="p">()&lt;</span>CR<span class="p">&gt;</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&#8217;ve read about it suggest that it&#8217;s excellent.</p> randy@rsontech.net (Randy Morris) Tue, 22 Sep 2009 00:00:00 http://rsontech.net/articles/comments-revisited $ABSROOT http://rsontech.net/articles/absroot <p>Now that I&#8217;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&#8217;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&#8217;s very annoying when you&#8217;d like to keep all of your self built packages in one place. I&#8217;ve come up with a workaround and I&#8217;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">&quot;$HOME/.absroot&quot;</span> <span class="nv">SYNCARGS</span><span class="o">=</span><span class="s1">&#39;-mrtv --no-motd --delete-after --no-p --no-o --no-g --keep-dirlinks&#39;</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&#8217;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&#8217;ve collected.</p> <p>If anyone knows an alternative solution, I&#8217;d be glad to hear it &#8212; I&#8217;d also like to know of any major side effects, so <a href="/about/">let me know</a> what you think.</p> randy@rsontech.net (Randy Morris) Tue, 25 Aug 2009 00:00:00 http://rsontech.net/articles/absroot AUR Insecurity http://rsontech.net/articles/aur-insecurity <p>Everytime I see a new user asking about the AUR on IRC I cringe. Not because I don&#8217;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&#8217;ve written an example below &#8212; the urls have been changed so you can&#8217;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">&#39;Something really awesome that you want to install&#39;</span> <span class="nv">arch</span><span class="o">=(</span><span class="s1">&#39;i686&#39;</span> <span class="s1">&#39;x86_64&#39;</span><span class="o">)</span> <span class="nv">url</span><span class="o">=</span><span class="s1">&#39;http://a.trustworthy.source.url/&#39;</span> <span class="nv">license</span><span class="o">=(</span><span class="s1">&#39;None&#39;</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">&#39;e6f64c753e4d6de8db6fc2e0d&#39;</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">&amp;&amp;</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&#8217;t going to catch it. Obviously <code>rm</code> is just one example of something malicious, it&#8217;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&#8217;ll never do it again. Hopefully the next time you wget &amp;&amp; tar &amp;&amp; makepkg (or hopefully <a href="/projects/slurpy">slurpy</a> &amp;&amp; makepkg) you&#8217;ll take a second and think about what you might be getting yourself in to.</p> randy@rsontech.net (Randy Morris) Wed, 05 Aug 2009 00:00:00 http://rsontech.net/articles/aur-insecurity Git Diff and Vim http://rsontech.net/articles/git-diff-and-vim <p>Now that I&#8217;ve seen the light and begun using git instead of subversion, I thought I&#8217;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&#8217;ve just reproduced it here to help spread the word.</p> randy@rsontech.net (Randy Morris) Mon, 13 Jul 2009 00:00:00 http://rsontech.net/articles/git-diff-and-vim Simple Todo http://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&#8217;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">&quot;add&quot;</span><span class="o">)</span> <span class="nb">echo</span> <span class="nv">$2</span> &gt;&gt; <span class="nv">$HOME</span>/.todo ;; <span class="s2">&quot;del&quot;</span><span class="o">)</span> <span class="nv">todo</span><span class="o">=</span><span class="k">$(</span>&lt; <span class="nv">$HOME</span>/.todo | sed <span class="s1">&#39;s/&#39;</span><span class="nv">$2</span><span class="s1">&#39;//;tx;p;:x;d&#39;</span><span class="k">)</span> <span class="nb">echo</span> <span class="nv">$todo</span> &gt; <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&#8217;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">&#39;{ i += 1; print i&quot;: &quot;$0 }&#39;</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">&quot;add&quot;</span><span class="o">)</span> <span class="nb">echo</span> <span class="nv">$2</span> &gt;&gt; <span class="nv">$HOME</span>/.todo ;; <span class="s2">&quot;del&quot;</span><span class="o">)</span> <span class="nv">todo</span><span class="o">=</span><span class="k">$(</span>&lt; <span class="nv">$HOME</span>/.todo | sed <span class="s2">&quot;$2&quot;</span><span class="s1">&#39;d&#39;</span><span class="k">)</span> <span class="nb">echo</span> <span class="nv">$todo</span> &gt; <span class="nv">$HOME</span>/.todo ;; <span class="s2">&quot;search&quot;</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">&#39;s/:/: /&#39;</span> ;; <span class="k">esac</span> <span class="o">}</span> </pre></div> randy@rsontech.net (Randy Morris) Tue, 07 Jul 2009 00:00:00 http://rsontech.net/articles/simple-todo Slurpy: An AUR Helper http://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&#8217;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&#8217;ll have something to do when I&#8217;m bored.</p> randy@rsontech.net (Randy Morris) Mon, 22 Jun 2009 00:00:00 http://rsontech.net/articles/slurpy-an-aur-helper Irssi Setup http://rsontech.net/articles/irssi-setup <p>I&#8217;ve had a few questions recently about how I&#8217;ve got my irssi configured. Instead of typing it out every time, I&#8217;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&#8217;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&#8217;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 &#8212; 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&#8217;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&#8217;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&#8217;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> randy@rsontech.net (Randy Morris) Tue, 24 Mar 2009 00:00:00 http://rsontech.net/articles/irssi-setup Vim Tip: Comments http://rsontech.net/articles/vim-tip-comments <p class="update"> I&#8217;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 &#8220;holy crap why didn&#8217;t I find this before&#8221; category&#8230;</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&#8217;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. &#8220;//&#8221;</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> randy@rsontech.net (Randy Morris) Thu, 12 Feb 2009 00:00:00 http://rsontech.net/articles/vim-tip-comments SVN Diff and Vim http://rsontech.net/articles/svn-diff-and-vim <p>Now that I&#8217;m starting to really get used to using svn for all my config files and web dev work, I&#8217;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&#8217;s a really sucky way to display it &#8212; 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&#8217;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&#8217;s default output you&#8217;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">&#39;svn --diff-cmd=/home/[username]/bin/svnvimdiff diff&#39;</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> randy@rsontech.net (Randy Morris) Mon, 22 Dec 2008 00:00:00 http://rsontech.net/articles/svn-diff-and-vim Me vs. GNU Screen http://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> randy@rsontech.net (Randy Morris) Mon, 24 Nov 2008 00:00:00 http://rsontech.net/articles/me-vs-gnu-screen Handling Urgency Hints http://rsontech.net/articles/handling-urgency-hints <p>Recently I found myself getting tired of <a href="http://pidgin.im">Pidgin</a>&#8216;s multi-window interface and began searching for alternatives. Because I&#8217;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 &#8212; no more color changing tags/taskbar. Enter urgency hints.</p> <p>I&#8217;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">&quot;fe-common/core&quot;</span> <span class="o">=</span> <span class="p">{</span> <span class="n">beep_msg_level</span> <span class="o">=</span> <span class="s">&quot;NOTICE MSGS HILIGHT&quot;</span><span class="p">;</span> <span class="n">bell_beeps</span> <span class="o">=</span> <span class="s">&quot;no&quot;</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">&#39;^G&#39;</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> randy@rsontech.net (Randy Morris) Mon, 17 Nov 2008 00:00:00 http://rsontech.net/articles/handling-urgency-hints