Coming back to vim

It's time for my monthly or so post! I wanted to go through and post about my OpenBSD firewall I built but that's not 100%. Also I'm not ready to go on about anything amazing with puppet because without my lab being done puppet isn't useful so lets go back to talking about my dev environment!

I know Justin has been asking for this for a little while.

Preface: Going "back" to vim

As a sysadmin at work I use vi a lot. Not even vim; vi. We have lots of unix boxes that default to vi as the installed editor and we don't just go installing vim on everything. Personally I use vim a good amount on my machine since I spend a lot of command line time anyways. I know more than just a few of the commands but I really only consider myself a second or maybe third year vim user1 since I never used it full time to write code. I live the motion and use things like ci[ and C-v 5j x but I still fail to use multiple registers, buffers, or tabs… or even the leader commands.

I'm an amateur software developer at best; I have serious aspirations about seeing if I have the chops to go pro but right now I'm honing edges. Irregardless of how developer or not I may be, I am developer lazy so I spend money on tools that make my life easier. I've been using PyCharm to help me write utilities and my mini apps and it's just the best. Sometimes I worry about leaning on IDE tools stunting my abilities so I took some time a month back to stand up and step back from PyCharm and instead just use vim…

This is the setup.

Part One: My keyboard

I use a slick trick on my Mac so I have no access to Caps and my CapsLock key acts as BOTH a Ctrl and Escape. If I tap the Caps it's esc, if I chord it with anything else it registers Ctrl… I pinkie reach for nothing. Here is the the instructions, 10.8 approved so YMMV for other versions.

  1. Go to System Preferences -> Keyboard -> Modifier Keys. Set Caps Lock to ^ Control.
  2. Install KeyRemap4MacBook - Software for OS X.
  3. In KeyRemap4MacBook, enable Control_L to Control_L (+ when you type Control_L only, send Escape. Search will help.
  4. Reboot and enjoy.

Part Two: The Development Server.

You didn't think I was just going to vim run.py and take off did you? No.

If I'm going to work from the shell I want to make it so I can work from anywhere while I am at it. I have a Mac OS X server that would love to be my dev box so away I go. Open some ports, SSH keys, virtualenv, python3 from brew… tada! But it's not ready yet.

OpenSSH is my best friend. I keep keys close at all times and use cools scripts on my laptop to help manage them. However SSH is not enough and this is where Mosh: the mobile shell comes in. Mosh isn't a total end to end transport solution but it's high speed udp style and local echo features make it supreme when then connection starts lagging and you don't want it to slow down your code. Best yet? brew install mobile-shell on both boxes… done…

If only we had a windows client already.

If you want some portable keys help check out the following;

Just remember to not make these your ONLY keys, all posable keys should be password encoded and easily revokable so keep a backup and list of your emergency to revoke when it gets lost.

Part Three: The Terminal

I need a sweet terminal so I use zsh with oh-my-zsh and a while bunch of personal mods. Remember the whole lazy part? Yes. Here is the highlights of my zsh configs;

The second major part is tmux. Whatever you are using now… drop it and use tmux. I remapped all my common tmux commands to vi-mode style and C-a for my leader because now ctrl and a are touching. For the full list of my configs which I won't get too deep into check out tmux.conf at master · tbunnyman/dotfiles · GitHub.

My main tmux window generally looks like this

     -----------------------
    |    Chat   |           |
    |     or    |           |
    |extra shell|    VIM    |
    |-----------|           |
    |           |           |
    |    IRC    |-----------|
    |           | MiniShell |
    =========================

Chat is my flux buffer that gets changed between a personal chat and second work buffer. IRC is my ever present wee-chat connection. The mini shell is a little shell I keep in the same dir as vim so I can quick run python -m unittest discover module over and over or whatever. When I'm playing with Flask it's running there. Depending on where my focus is the vertical split is usually about 65% weighted to the work to squish distractions without cutting them all out or I am on the 11' MacBook Air screen instead of a 20+' external display.

I often have a second window but the latest version added C-a z for window zoom and that's GREAT when I really wanna focus on something or blow up the mini-shell while I am debugging something.

Part Four: Into VIM

First and foremost I keep an 8.5x11 copy of Beautiful Vim Cheat-Sheet Poster & Printable Downloads on my desk. It's a nice way to keep reminding me of all the features I NEED to be using and if you don't want to give someone 10USD for it there is a free link right on the page for a low res.

tl;dr the configs

dotfiles/vim at master · tbunnyman/dotfiles · GitHub

A lot of my inital vim config like most was stolen from somewhere but over time I have stripped out everything I didn't adapt in. I started with YADR and then seriously hacked it to death. In the end there is still yadr references but you shouldn't take anything that claims being from yadr in there still is. I'm just lazy about renaming files for scuz.

Highlights

There you go! I know it feels like I'm skimming the VIM part of the vim writeup but there is really only so much you can do TO VIM itself. It's the development environment you put around it and what you put out with it. Hopefully I will be putting out great things once I learn how to use tags and rope and all that other stuff to get back to ultra fast code sifting and editing.

Part Five: Wishlist

Auto-running tests

Just something that PyCharm and Komono before that spoiled me on. :w running my tests since I very often TDD would save a lot of window jumping

Snippits

I'll never get deep code intelligence with vim and that's kinda the point but PyCharm saved somewhere around a billion keystrokes when you learned when to hit the auto complete right.

Part Six: Warnings

This allows me to do some awesome stuff and so far I am happy with with it outside of a few small caveats.

  1. It's damn fiddly. So much and learn and fiddle with distracts from the work.
  2. Sometimes cruising around inside of vim, inside of tmux can make for some finger dancing that I don't care for; C-a l C-a k C-w l… until I trip over my own keystrokes. C-a ; is really useful when popping between panes when it comes to mind

Part Seven: Going forward

I can connect in technically from anything I trust enough to plug my key jump-drive into. I currently have bought a YubiKey and am seriously considering switching right over to two-factor OTP which makes me LESS afraid of plugging in the key into something.

Another area I am considering going forward with is I technically won't even need my computer to work. I could just work with my iPad and a keyboard! I'm really sure these articles had just a little bit to do with my idea of moving over to all command line vim. I don't know if I am there but it is tempting;


Was this more in depth than you expected? Do you want more? Lemme know.


  1. See Just Use Sublime Text - Andrew Ray's Github Blog for details on what I mean by that. 

Tagged ,

SSH Keys on a USB jump drive on Mac OS X Part 2

All right! You read my post SSH Keys on a USB jump drive on Mac OS X (Mountain Lion Edition) and want to take this to the next level huh? Maybe having your config posting back to a jump drive and having to have it plugged in every time you want to log into something is sooooo lame! You often just leave it there, plugged in when you walk away from your work station. There has to be a better way…

I got you bro

What you need to be doing is adding your keys to ssh-agent on demand then pulling your key except for when you REALLY need it. But how do you do that easily?

I got you bro

Windows

Lets start with the basics. PuTTY Download Page - Pageant

  • Download it.
  • Install it.
  • Yes you have to use their crappy ppk so set that up.
  • Start Pageant then load your ppk version of your key.
  • Eject drive.
  • open new session, don't bother manual adding key.
  • Party time
  • Excellent

The cool part is that Pageant remembers your keys so if you pin it to the start menu then it's highlight, over enter, password… you get the point.

The shitty part is it keeps that key loaded until you reboot. That's ULTRA fucking weak. Sorry windows. If anyone knows better give me a shout out.

Linux

Linux is easier and way better. Lets assume you do everything in the command line so.

alias loadkey=ssh-add -t 30m /mnt/whatever/ssh/$1

then all you have to do is

loadkey keyname

then POW!!! for 30 minutes you have you key loaded. See the 30m in the command? Change that for maximum moddage of commands. Are you a lazy brogrammer slash skriptkiddie and need the time format table?

Bro… got… you are… by me

<none>  seconds
s | S   seconds
m | M   minutes
h | H   hours
d | D   days
w | W   weeks

Time format examples:
600     600 seconds (10 minutes)
10m     10 minutes
1h30m   1 hour 30 minutes (90 minutes)

Damn! Yea….

Mac

Ok, this is where the gold is. I slaved over a hot mess of applescript to you guys this so feel the love bro. Since it's my Mac and I wanted key exchange to be as easy as possible I pulled out all my scripting to invoke MAXIMUM lazy.

Maximum lazy engage!

Ok. To start there is no ssh-askpass on Mac OS X Mountain Lion which is fairly un-bro of apple but whatever. I replaced it with an applescript I stole and slightly tweaked to run better.

Take this, it's dangerous to go alone. tbunnyman/mac-ssh-askpass · GitHub

Just put it in ~/Applications like me or /usr/local/bin or where ever makes you warmest and fuzziest inside. Either way don't forget where you put our makeshift ssh-askpass

Now break out the applescript editor and take this puppy for a ride.

(*
This key adding mini program indexes the keyfiles on your jump drive
then prompts you for what one you want to load into ssh-agent

You need mac-ssh-addpass for this to work as well
https://github.com/tbunnyman/mac-ssh-askpass
*)

property keyFolder : "KEYDRIVE:ssh"
property askPass : "$HOME/Applications/ssh-askpass"
property keyTime : "1h"

tell application "System Events"
  set theList to the name of every item of folder keyFolder
  set theKeys to {}
  repeat with i from 1 to the count of theList
    set theFile to {item i of theList}
    if (theFile as string) ends with "pem" or (theFile as string) ends with "_dsa" or (theFile as string) ends with "_rsa" then
      set end of theKeys to theFile
    end if
  end repeat

  set frontApp to short name of first process whose frontmost is true
  tell application frontApp
    activate
    set theKey to choose from list theKeys with title "Choose your Destiny" with prompt "What Key do you want to activate for " & keyTime default items {first item of theKeys} without empty selection allowed and multiple selections allowed
  end tell

  do shell script "SSH_ASKPASS=" & askPass & " /usr/bin/ssh-add -t " & keyTime & " \"" & {POSIX path of folder keyFolder} & "/" & theKey & "\""
end tell

Now pay attention or this will hurt.

The keyFolder property is in Apple's format because it just worked better that way. It needs to point to the folder that has all your key files. The format is drive:folder:subfolder:youget:theidea. Now make sure to set that and the location of our new ask-pass. Also because I was a lazy scripter the filter is hardcoded. If your key files end in anything other than .pem, _rsa, or _dsa you are perfectly legit but I hate you anyways and you will need to edit the nasty (theFile as string) ends with blah line.

Now... toss this applescript in your scripts folder and set the hotkey ctrl-opt-k in FastScripts and if you don't have it then shut up and go buy it in thanks from having this awesomeness rained down upon you… or put it in Alfred App... whatever bro; the point is you should be running all your shell and applescripts from the keyboard so do it.

Now hit that key command and watch the awesome of the menu box you can arrow through! Select your key of the minute and hit enter! Be amazed at the applescript password prompt.

Feel amazing bro. Feel amazing.

Note for those who are curious.

The applescripts are hooking off the frontmost application. IE it's telling whatever app is in front to activate1 and then display the dialogs for the scripts. So don't bug out because the icon displayed is some "random seeming" app on your system. I do this so that the box is always to front so it can be keyboard operated and drops you right back into your front most app without fuzzing off the focus elsewhere or in some truly random app of my choosing like Finder.

I'll probably put this in my GitHub later, or forget and leave it as a blog exclusive so enjoy.


  1. I had some weird edge case focus issues and making sure to activate before springing the next dialog box smoothed it all out. Sorry if that has any weirds, it really shouldn't 

Tagged

Update to my Transmission Tools

Nope, not something to help unmount and flush your transmissions, it's some tools for Transmission, specifically MY tools.

I just though I would share that I redid this repository completely and cleaned up the Move & Stop script to cover some possible bugs and be a bit more python modern. If you had any problems with it not moving single files or just wanted some slightly cleaner code go grab the new version.

I should really break out TransmissionRequestWrapper into it's own package and distribute that since it's so sweet. Please feel free to use it with some credit.

tbunnyman/Transmission_Tools · GitHub

Tagged , ,