22 May 2012

Why I love Open-Source Software

Open-source software is wonderful. For example, I needed to batch convert 700 AutoCad files (DWG) into regular image files.

Step one: Find library to do this for me. Succeeded by finding cad2svg. Can’t run as its compiled in OSX, can’t recompile b/c it has unavailable proprietary blob. Read author’s blog & README. He states that it was developed in Red Hat Linux/ Fedora. Blog is dated ~ 2009.

Off I go to grab Fedora 12. Install in virtual machine, set up shared folder between host and vboxclient. Use script like find . -name \*.dwg -print0 | xargs -0 cad2svg - OUTPUT.svg

Then jump back into OSX to use a library from Cairo 2d image library, svg2png. This will convert them into png images.

Do some googling for correct imagemagick settings to invert the image, convert all non-white to black, and then convert to monochrome.

Spent a few minutes tweaking the settings, order of events, properly piping the output image from svg2png into imagemagick… and voila! Computer is currently chugging through all 700 conversions. Command to convert from svg to png (with tweaks) svg2png -w8000 '#{item}' | convert png:- -negate -fill black +opaque white 'svgs/#{output}.png' (Note: Piping these two commands saves writing temp file to hard drive) ImageMagic, svg2png, cad2svg (except proprietary blob) are great tools made even greater by their Unix philosophy (doing one thing well and using standard-in and stdout to chain together commands)

21 May 2012

5 Days of OSX

Well, it’s been 5 days since getting an OSX laptop (MBA) and it’s treating me pretty well.

Here are some initial impressions: Some of the coolest things: 1. Spotlight 2. Quicksilver (launcher app) 3. Quickcursor (vim geek app lets edit with vim everywhere… like this an email or blog post) Thanks to Conner’s Blog4. Touchpad is magnificent… crazy amount of multitouch gestures 5. System based on BSD Mach kernel… allowing all sorts of Unix-compliant goodness Along with that goes MacVim, iTerm2, growl, and all my unix commandline favs 6. Homebrew and MacPorts… both very good but not as well integrated as Debian’s apt-get and Arch’s pacman. Oh well, still waiting for slick Linux laptop with the hardware support of OSX…(not holding my breath)

What’s not so cool: 1. Learning new keyboard shortcuts 2. Fn key is a complete waste of space, need to remap it to be Ctrl (Did this with KeyReMap4Macbook: Note that the config can be tricky depending on other keyboard tweaks, but it’s now working) 3. Logitech mouse is a bit tweakier than under Linux & windows. (Update: MagicMouse looks pretty cool, esp with multitouchtool) 4. Terminal based VIM is SegFaulting with one of my addons (it allows me to blog from commandline for blog.xargs.io, my tech blog. Thankfully it works ok in MacVIM). Haven’t solved this yet but with it working for 99% of my tasks… the troubleshooting can wait for a rainy day. Maybe updating Mac’s pre-installed python…and recompiling VIM.

21 May 2012

Using ZSH's History Incremental Search with Vi-Mode

I switched to ZSH a few months back and am spending more and more time in commandline + VIM/MacVIM.

Once I added the tag to my dotfile to force vi-mode on the commandline I lost the ability to do incremental searches of my zsh history. So here’s the fix which saves lots of typing:

First, the regular keybind to allow Ctrl-R to enter history search backward mode: bindkey "^R" history-incremental-search-backward

To fix the fact that the prior keymap no longer works in vi-mode zsh, add this to a zsh config: bindkey -M viins '^R' history-incremental-search-backward bindkey -M vicmd '^R' history-incremental-search-backward

Now I can ^R with aplomb…

This is thanks to the explanation from JDeBP over on superuser.com.

20 May 2012

Useful VIM cheetsheet

New VIM command of the day: d/(searchterm) This will delete up until the search term.

Source of this wisdom: VIM Commands

20 May 2012

VIM Video by Bram

Watched this video today by the author of VIM: Bram MoolenaarVIM Video by Bram Moolenaar

It’s about 1.3 hours long and worth the watch.

A useful tip so far is the \*

Which uses your current word as a search term and incremental searches forward.

12 May 2012

Keeping Track of Config Files with Git and Dropbox

Dotfiles are all the rage right now on Github, and for a good reason. They’re the files that allow you to configure your Vim, Linux, Mac, etc. They’re simple textfiles written in a specific format for each given application. Being a textfile they’re easily added to a version control system like Git or Mercurial and changes can be tracked, commited, diffed, etc.

How does it work? Make a folder in your Dropbox folder and place config files there.

mkdir ~/Dropbox/dotfiles
mv ~/.vimrc ~/Dropbox/dotfiles/.
ln -s ~/Dropbox/dotfiles/\* ~/.

The first command creates the folder. The second command moves the .vimrc configuration file into that folder. The last command symbolically links all files/folders inside the dotfiles folder into the base of the home folder, ie /home/tevic/.

Add all those files into a git repository via a git init; git add .; git commit -m "Initial Commit with Vimrc". Now you can also use git for tracking changes on various branches.

I’ve been very happy with storing my vimrc, zshrc, ~/.config/zsh.d, ~/.vim/ configurations in Dropbox. Switching to a new computer or reconfiguring is no effort whatsoever.

12 May 2012

My current favorite VIMRC one-liner

Very handy for quickly swapping between prior file and current file in VIM:

Add the following to VIMRC: nnoremap <leader>, :b#<cr>

My current leader key is set to comma (,) so punching ,, switches between prior and current file, or back again.

Runner up for other good one liners: inoremap jk <esc> This one allows you to stay on the commandline and ESCAPE out of insert mode by using key combo ‘jk’!Note: I find this faster than a more common binding of ‘jj’ for this purpose. With jj the same finger needs to activate the key in quick succession. With j & k the right hand index and middle finger both activate at a similar time. Thus my preference goes to the slightly easier and faster option.

Source & Credit: Gary Bernhardt’s Dotfiles on Github (though escape sequence of jj swapped to j k)

PS - The only conflict I’ve had with j k being an ESC sequence is this blog post. In code and prose I haven’t run into problems.

07 May 2012

Slick ZSH Trick for Vi-Mode

Found a neat trick today for making the commandline vi-mode much more friendly.

Back-story: As I’ve been spending more time programming, I find myself more comfortable on the commandline and in VIM. Also, there’s a setting that can be placed in .bashrc and/or .zshrc to allow vi style editing of the commandline. This is all well and good but without any visual indicator of whether I’m in INSERT MODE or NORMAL MODE… well, it’s disorenting.

So the neat trick is to add code in your .zshrc to insert a right-hand side prompt (RPROMPT) that will show a notifier depending on what mode you’re in.

Add the following code (and thank you to wherever I found this trick online)

    function zle-line-init zle-keymap-select {
        RPS1="${${KEYMAP/vicmd/--NOR--}/(main|viins)/--INS--}"
        RPS2=$RPS1
        zle reset-prompt
    }
    zle -N zle-line-init
    zle -N zle-keymap-select

Have another nice trick for your .zshrc, please share it in the comments!

29 Apr 2012

Easier Directory Navigation

Source: http://stackoverflow.com/questions/3986760/cd-1-2-3-etc-in-z-shell

While looking for a zsh compatible way to replace AutoJump with a ZSH compatible option, I found the following: setopt autocd setopt AUTO\_PUSHD The first option allow moving into a new directory by directly typing it’s name without ‘cd DIRECTORY’.

The second option allows easier navigation using ‘dirs -v’ to check for recent directories or cd ~+<tab> for tab completion jumping :).

Another little way to save small repetitions!

As a side note: I’m quite sad not to have the flexibility of AutoJump in my repetoire with ZSH. It’s the only feature I find lacking compared to BASH. Hopefully it works better in ZSH in the near future, or hopefully I can look into why it doesn’t work and learn how to patch it.

28 Apr 2012

My Kingdom for a Good Fuzzy Finder

I’ve been working on my VIM configurations recently which involved cleaning out cruft from when I hadn’t transitioned to using Pathogen. While doing so I realized that I wanted to take the advice of DestroyAllSoftware.com and switch away from Nerdtree to something that doesn’t involve a context switch. CtrlP to the rescue! Slick addon that I’m happy to have in my arsenal. Plus, it didn’t necessitate installing and configuring VIM with Ruby 1.8.7 as Command-T did :).