Oct 27, 2010

Tab Completion for Dhiraagu WebSMS Script

A LONNNNG LOONG time ago (two years specifically) I wrote a bash script that would allow me to send websms's on the command line.

This script has been working perfectly for me since the day I wrote it. However, the problem was that my "directory" file had started to grow a little out of proportion, and I started having trouble remembering all the aliases I put in it. So I wanted to enable custom tab completions on the script.

Enter this tiny bit of code.
All you have to do is insert the following at the end of your bashrc file (usually in ~/.bashrc)

complete -F _bdwsmscomplete websms
 local WSMSDIR="$HOME/.wsmsdir" #change accordingly
 OPTS="-h -v -s -d -u -p -n"
 CONTACTS="$(cut -f1 -d',' ${WSMSDIR})"
 if [[ ${CUR} = -* ]]
  COMPREPLY=($(compgen -W "${OPTS}" -- ${CUR}))
  return 0
 case ${PRE} in 
   COMPREPLY=($(compgen -W "${CONTACTS}" -- ${CUR}))
   return 0
   COMPREPLY=($(compgen -W "-n" -- ${CUR}))
   return 0

 return 0

If everything went well, you should be able to hit the [TAB] key while at the -n option and it'll automatically try to fill in the name of your contact.Enjoy!

P.S You'll need to re-open the terminal.


Anonymous said...

Recently a video has been posted on youtube showing a disgusting renewal of vows in the Maldives. The way the international media, daily mail and the evening standard took the story gave the wrong impression of Maldivians to the world.

Heres a video response to that: http://www.youtube.com/watch?v=GD7rOxXvPmk
This video shows a side of Maldivian culture that is true and hardly ever spoken of. The TRUE MALDIVIAN. Its taboo because we are supposed to be a 100% muslim country. But see for yourself..

Anonymous said...

campaign hingiyas bodu varu! saabas.

Anonymous said...

Since most people copy and paste believing in the coder and not checking the code, I think you should change ' local WSMSDIR="/home/kudanai/.wsmsdir" #change accordingly' to 'local WSMSDIR="~/.wsmsdir"'!

SoE said...

noted. Done. lazy work on my part.

Post a Comment