Showing posts with label curses. Show all posts
Showing posts with label curses. Show all posts

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