Skip to content

Instantly share code, notes, and snippets.

@levicole
Created July 18, 2011 13:56
Show Gist options
  • Save levicole/1089589 to your computer and use it in GitHub Desktop.
Save levicole/1089589 to your computer and use it in GitHub Desktop.
# vim:set ft=sh sw=2 sts=2:
# My own version of a little todo script. Basically just grabs a file in the
# $TODOS_DIR Right now, my $TODOS_DIR is set in my .bashrc
todo(){
cd $TODOS_DIR
vim $1
}
_todo()
{
local cur lists
[ -r "$TODOS_DIR" ] || return 0
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# Being the not awesome shell scripter, I opted for ruby here. Just grab all
# the files with the .todo file extension. The purpose for the file extension
# is for writing a vim plugin some day.
todos=$(\ruby -e "puts Dir.glob('$TODOS_DIR/*.todo').collect{ |f| File.basename(f) }.join(' ')")
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -o filenames -W "$todos" $cur) )
fi
return 0
}
complete -F _todo todo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment