Saturday, August 18, 2012

Interactive selection for ASCII lines using python

Recently I found this nice curses based directory bookmarking tool called cdargs.
I thought it will be nice to have interactive selection for the list. For my bash functions which shows list. Like I have a bash function which can show me a list of clearcase view and then I can choose one of them. That is all bash. But it would have been nice if the list was little interactive and I could have moved around. So I found curses to my help and found another nice tool called iselect.

Iselect does what I need but it does not show the line number like cdargs, so you cannot really select a line by pressing a number. I googled and realized that I can pretty much do the same stuff in python. Since there was no available open source python tool which I can customize to my need, I thought of writing my own. I call it pyselect. It is work in progress and tries to do things like cdargs and iselect. But more customizable and smaller, after all it is scripting in python.

You can checkout the git : https://github.com/jayrajput/pySelect

It is still a work in progress but does not look difficult till now.
The current version as of 18Aug2012, lets you interactively lines fewer than 30.

VIM: Cdargs

Cdargs is a curses based directory bookmarking tool. See http://www.skamphausen.de/cgi-bin/ska/CDargs/

This works nice on bash but I wanted something like that to work with VIM. Tried NERDTree bookmarking but still wanted something like curses. Press a key a list is displayed where you can move around. Something like screen window list shown on pressing C-A+"

I found it that it was way too easy to integrate cdargs with vim using a vim function. The function is self-explanatory. Read the see links and you will be able to decipher the function.

" See http://vim.wikia.com/wiki/Write_your_own_Vim_function
function! Cd()
    exe "!cdargs"
    let mydir = system("cat /home/jay/.cdargsresult")
    " See http://stackoverflow.com/questions/4596932/vim-cd-to-path-stored-in-variable
    cd `=mydir`
endfunction
" Alias to my function so you do not need to type call everytime.
command Cd call Cd()


There is also  VIM plugin which uses cdargs but it does not show the curses window. See: https://github.com/vim-scripts/cdargs

Sunday, August 12, 2012

Check files taking up space



There are multiple way to check for files taking space.  Linux command du seems to be the best.
Here is the du command from the LinuxCommandOrg


du -s * | sort -nr > $HOME/space_report.txt


du also has option which can skip NFS mounted dir. See du man page.

Monday, August 06, 2012

Vim spell check with PHP not working

Vim 7.0 has on the fly spell check which can be enabled by using ":set spell". You may also want to use "sell spelllang=en_us" but ":set spell" just works fine for me.

But this on-the-fly spell was not working with my .php files which have the PHP start tags (less than question mark sign). Without the PHP start tags everything was fine.

Here is the workaround to highlight bad spelling in .php file with PHP start tags:

:set filetype=cpp
:set spell

You lose some of the php filetype goodies but now you have the spell check.

I also found that the php filetype was not working for me as the comments environment variable was getting set to HTML comment style (less than exclamation dashes and dashes greater than) .