Git Ready and the ZSH Prompt

Posted by matt
on Friday, January 30

Git is one of those programs, like, say vim, which contains more functionality than it seems humanly possible to grasp. Thankfully, there are sites like gitready, which are designed to help us mere mortals to grasp the awesomeness.

I’m very pleased to be able to report that a bit of awesomeness that I’ve been involved in has been listed. Have a look at the ZSH Git Status page and you might see what I mean. That’s right: zshkit is mentioned.

If you’ve not read any of my other posts on it, zshkit is a project, started by Bryce “BonzoESC” Kerley, and forked by various people (I think I just had the honour of being the furthest up the network graph).

Over the next few days, I’m hoping to implement the vcs_info stuff mentioned in the git-ready comments.

ZSH Abbreviations

Posted by matt
on Friday, January 23

Abbreviations are ZSH feature I just stumbled across, whilst proselytising about GRML, a cool linux distro.

Here’s a snippet to show you the ultimate power they offer:

OK, so it may not make much sense as it stands, but bear with me. Suppose you want to get some information about the size of the directory tree you’re in. Now, you want to use something like du -sch, traditionally, you might have alias da='du -sch' in a config. file, but what if you want to edit it at the last minute. The abbreviation lets you do just that. If you type da,., the ,. trigger expands the abbreviation to give you du -sch on the command line, and then you can further edit the command, to add that extra x, or whatever, afterwards. This is obviously a somewhat contrived example, but the effort saving, productivity enhancing idea is still there, and it fits in well with the ZSH philosophy, or my version of it at least.

To see what I mean, look at the magic-space command. If you use:

    bindkey ' ' magic-space

Then use history, or some other shell expansion, it will be fully expanded when you hit space. Did you miss the colon on the end of that scp command three lines ago? No problem, hit !-3␣, add it, and hit return. It feels similar to the abbreviation mechanism above, and is very powerful too.

It’s worth noting that the original sighting of this trick doesn’t seem to be compatible with the ‘magic-space’, since it rebinds space.

You can find all of this, and more, in my zshkit.

My top 5 ZSH tips!

Posted by matt
on Monday, October 27

Since reading this question on stackoverflow I’ve been intrigued by zsh, and looking at cool things it can do to make my life easier. I decided to jump on the top-n things bandwagon and publish a quick list of zsh bits I find really useful.

Here’s a quick list of my top five tips:

  1. Try using zsh’s awesome for loops:
    for file (prefix*) $file:s/prefix/new_prefix/
    or if you want more than one command in the body, try:
    for file (prefix*) {one; two; three}
  2. Use numerical ranges for operating on batches of files:
    {0..10}
    will give you a range of values, which you can use in a loop (for n ({0..10})), and
    <0-10>
    lets you match ranges of digits in filename globs.
  3. Use variable replacements to quickly munch filenames
    $variable:s/thing/other_thing/g
    But alas, there’s no support for regular expressions in these.
  4. Try globbing instead of using find:
    **/*.png
    will find all png files beneath your current directory. You can use this in a loop too:
    for f (**/*.txt) {echo $f}
  5. Use zsh-lovers to find out more. There’s far too much to zsh for me to be able to list it all here. My first stop is usually this man page, and it’s usually all I need.

  6. Bonus! Google for zshrc config files. Try github and dotfiles first.

Z-shell productivity: the prompt and title

Posted by matt
on Monday, October 13

I’ve recently been playing with a cool project on GitHub: zshkit . It’s a basically just way of organising your zsh config files, but it’s inspired me to look at improving my shell productivity and I hope to post a few times about this.

One of the many changes I made to my fork of zshkit, is to minimise the prompt. It’s something I’ve not really considered before, and I’ve pretty much always used something a lot like gentoo’s default. Here’s a screenshot of my new prompt and title:

Minimalist Prompt

The top line shows the prompt when outside of a git repository and the bottom shows how it looks from within one. Normally, it shows the current directory on the left and the last command’s exit status (a yellow $ means a failure). When I’m inside a git repository, it shows the current branch, with the branch name coloured cyan when the repository is clean and magenta when there are pending changes.

This only really works when coupled with a decent title in your terminal. Whilst looking around, I found _why’s which seems to work really well and is what you can see at the top of the screenshot. The next step would seem to be _why’s screenrc, but I don’t really ever use screen, despite being aware of the awesomeness.

My prompt is it github, with everything else:

  • prompt_git_setup
  • to use it, you need something like this: git-prompt
  • and something like this in your rc files:

    autoload promptinit && promptinit && prompt git
    

It’s probably easier to fork your own zshkit and go from there.

History meme redux...

Posted by matt
on Wednesday, June 04

Following on from ones zeros majors and minors and Panasonic Youth, I humbly present my top 10 zsh commands:

    matt@pyxis ~ $ history 0 | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | \ sort -rn | head 
    2151 l 
    1376 cd 
    631 git 
    463 echo 
    343 open 
    341 mate 
    279 sudo 
    258 gnuplot 
    243 ll 
    241 rm

Interestingly, it’s quite different on my work linux box:

    1437 ls 
    1009 cd 
    315 svk 
    289 sudo 
    203 vim 
    189 rm 
    182 grep 
    178 mv 
    133 gvim 
    131 feh

And it depends on what I’m up to at any given time :)