My Top 10 Shell Commands

July 20th, 2008 by Les

I came across this over on Planet Ubuntu from Ubuntu hacker Edward Robinson.  Entering the following pipeline into your bash terminal will give you the sorted list (by invocation count) of the top ten commands issued in your history:

history|awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head

Here’s my list:

111 ls
109 cd
57 vim
41 make
20 svn
18 sudo
14 patch
12 rm
12 gnome-mud
9 ./configure

I only had by bash history setup for 500 history items but I’ve upped it a bit now. I’m curious to see what my long term usage pattern looks like!

Code Completion with VIM 7

July 20th, 2008 by Les

Code completion, also called by some ‘intellisense’, is easily setup in VIM for C/C++ files (its setup-able for essentially any language but since I am mostly a C hacker this is what this will cover.)

In Vim 7 the vim team released something called omnicompletion.  What this does is that it allows you to create an omni-function that is called whenever the omni-completion command is executed (C-X C-O by default).  The reasoning behind this is that it provides a mechanism for generic completion support rather than any particular implementation.   Since VIM is used by a great many people there are at least that many use cases for omni-completion this gives the user the power to extend their editor to allow for any sort of completion setup they might desire (albeit with sufficient technical knowledge to preform the setup).

A key tool to VIM’s omnicompletion abilities is the use of Exuberant Ctags.  For those who do not know, this utility scans source and header files and creates an optimized representation of interesting bits that other programs can use to do likewise interesting things.  So to start with the setup lets look at how to create a tags file that usable by VIM.

Lets say you want to have GTK+ intellisense in your editor.  The following incantation will create the tags file for you:

 ctags -R --c++-kinds=+p --fields=+iaS --extra=+q /usr/include/gtk-2.0

This will recursively scan every header file in the gtk-2.0 directory and create tags for every function, definition, and structure contained in there and it will spit out a file called tags in whichever directory you ran this.  I would recommend renaming this file to gtk+.tags or similar.  The parameters we pass to ctags specify which type of information we want to collect.  The reason for those particular parameters is that they provide the data the a VIM plugin called omnicppcomplete needs to functions which we will cover shortly.

Now that you’ve generated the gtk+.tags file place it whereever you would like to keep it.  VIM will always look for a file named tags in the current directory but for these sorts of tag files (whole interface dumps) it’s better to include them in your .vimrc like so:

set tags+=/path/to/gtk+.vim

You can create multiple files for each library you want completion for, or you could simply create a single tag file for the entirety of /usr/include.  Be warned using a huge /usr/include single tags file could slow down things considerably depending on your hardware.

Now that our GTK+ tags are setup we need to install omnicppcomplete.  This is a VIM plugin that provides an omnifunction for C and C++ languages obviating the need for us to create our own.  Once you have installed this (simple extracting it into your .vim folder for the most part), you now have intellisense for GTK+ like so:

 

VIM GTK+ Completion

Isn’t progress exciting ;)  Remember that VIM also looks for a tags file in the current directory.  So if you wanted to add completion support for your individual projects its as easy as creating a tags from your source tree.  I setup a key command (C-F6 in my case) that will generate this for me while I am in a VIM session so as I update structures and functions I always have current completion:

 map <C-F6> :ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

Omnicppcomplete is smart enough to start completion when it encounters an -> or . in the code so it really is like intellisense when you’re using it.  To complete a function name you’ll still need to hit the omnicompletion command sequence but otherwise it Just Works:

VIM Project Completion

 

Finally, and this is a matter of personal preference, but one of the reasons I use VIM over EMACS is that command sequences that involve lots of Control/Meta/Shift/Alt stuff annoy the hell out of me.  So in my case C-X C-O has to go away.  I use a function that maps the tab key  in a SuperClever way that I got from the book Hacking Vim by Kim Shulz which is a great repository of various VIM tips and tricks.  What this function does is that if there is no completion that could happen it will insert a tab.  Otherwise it checks to see if there is an omnifunction available and, if so, uses it. Otherwise it falls back to Dictionary completion if there is a dictionary defined.  Finally it resorts to simple known word completion.  In general, hitting the Tab key will just do the right thing for you in any given situation.

To get this functionality just add the following to your .vimrc:

 function! SuperCleverTab()
    if strpart(getline('.'), 0, col('.') - 1) =~ '^\s*$'
        return "\<Tab>"
    else
        if &omnifunc != ''
            return "\<C-X>\<C-O>"
        elseif &dictionary != ''
            return "\<C-K>"
        else
            return "\<C-N>"
        endif
    endif
endfunction

inoremap <Tab> <C-R>=SuperCleverTab()<cr>

And there we have it.  A full, quick, and fast ‘intellisense’ setup in Vim.  I use this in my hacking every day, its really changed the way I work with Vim. If you’re a vim afficiando you really ought to give this a go.

 

Activity?!

July 20th, 2008 by Les

Thanks to Jeff Waugh I am all set up again to use this blog.  I have lately been doing an absolutely ton of work on gnome-mudJordim thinks that I should give Foundation membership another go once the .11 release comes out and that I should easily become a member.  I don’t want to get my hopes up too much I suppose but its exciting to hear anyways.

Anyway, the .11 release of gnome-mud is imminent!  It represents a huge amount of work as it is essentially a complete rewrite of gnome-mud from the ground up.  .11 could be considered the ‘KDE 4.0′ release of GnomeMud in as much that we lose a few features (very few luckily) but have a much stronger base to work on for future development.

Some of the big new features in GnomeMud 0.11 are:

  • Full MSP (Mud Sound Protocol Support) – We use GStreamer for this, playbin is absolutely amazing for how simple it is.
  • SOCKS Proxy Support (Finally! Version 4 and 5)
  • Zenith Mud Protocol (ZMP) Support – Just the core package for now but that’s only because noone is making packages for it. This is a real shame. ZMP uses the TELNET protocol 100% correctly by passing all information through Telnet’s subnegotiation mechanism.  This is in stark contrast to more popular MUD protocols like MXP and MSP which send all their information in-band so the client has to strip it out or the user will see the output. They also use a really cumbersome pseudo-html/xml format that is a real mess.  The only benefits I honestly think they have is that they are the most used extension protocols. Sigh.
  • Full Encoding Support – We now support proper encoding for our VTE widget so character sets can be rendered correctly.  We also support the TELNET CHARSET option which allows for character set negotiation (which is pretty cool), but mud server programmers being mud server programmers, noone actually uses this great option.
  • Auto-sizing text entry widget – This works like the entry in Gossip. It automatically changes its height based on the amount of text entered.  We have it set to a 5 line maximum at which point it’ll start to scroll. A minor but neat feature :)
  • Input History – We have bash style input history on a per connection basis now. Woo!
  • Nice new icon – Andreas was nice enough to give us a great looking tango-fied icon for this new release.

For the full list just visit our wiki page.  This gives us a great base to start on.  We’re still a long way from GnomeMud 1.0 but after this release comes out we are much closer because this is officially our Not Dead Yet release that’s going to kickstart the new era of GnomeMud development.

Arrival

January 4th, 2007 by Les

Well we made it up. The move was really smooth. I feel a little disconnected from the world. Our dsl/voip phone won’t be connected until the 15th so about two weeks of exciting waiting for them.

Found a cute coffee cafe with free wifi (where I’m typing this now!) so at least I’ll have some internet access for the mean time.

Hope everyone had a happy new year and I’ll talk with you all soon!

Moving!

December 29th, 2006 by Les

Well I’m moving to Olympia tommorrow and won’t have internet access until they connect our DSL.

So I shall see you all very soon hopefully from my brand new apartment!

Happy Christmas!

December 25th, 2006 by Les

I’m sitting at my parents house and I’m going to enjoy a tasty christmas dinner soon. Always nice to be with family at the holidays.

Going to have two additional days of Christmas mania when we go over to Charity’s family events.

Then we have a couple of days to finish packing and we’re OFF…

Crazy, crazy week.

Merry Christmas everyone :)

g_printf("Hello, World!\n");

December 24th, 2006 by Les

Well the GNOME accounts folk gave me an early Christmas present this year with this shiny new blog.

I expect it to be something similar to most open-source developer blogs.

I still have no word on my GNOME foundation membership application but with the holidays and the recent elections it will probably take a bit before the membership committee convenes to look over it.

Hopefully they won’t just say no!

Currently I’m working on some stuff for the great glade3 project as well as doing some hacking on GnomeMUD. glade3 could really use some more devs as the project gets bigger so be sure to go check it out if you’re inclined and want to help. Tristan doesn’t bite!

Starting school again in January and I end the year with a HUGE move for me up to Olympia.