Permalink
Browse files

Updates shell completion for ack, cheat, rake

  • Loading branch information...
1 parent 8ef4818 commit d4fe01c2ca6e96fe4c45fc603a5310fbe882e7a4 @pengwynn committed May 18, 2012
Showing with 34 additions and 7 deletions.
  1. +10 −0 zsh/functions/_ack
  2. +4 −0 zsh/functions/_cheat
  3. +20 −7 zsh/functions/_rake
View
@@ -0,0 +1,10 @@
+_ack() {
+ if (( CURRENT == 2 )); then
+ if [[ -a tmp/tags ]]; then
+ compadd $(cat tmp/tags | awk '{print $1}')
+ fi
+ else;
+ _files
+ fi
+}
+compdef _ack ack
View
@@ -0,0 +1,4 @@
+_cheat() {
+ compadd $(cheat sheets)
+}
+compdef _cheat cheat
View
@@ -1,8 +1,21 @@
-#compdef rake
-if [ -f Rakefile ]; then
- recent=`last_modified .rake_tasks~ Rakefile **/*.rake`
- if [[ $recent != '.rake_tasks~' ]]; then
- rake --silent --tasks | cut -d " " -f 2 > .rake_tasks~
+# Lifted from https://github.com/joshuaclayton/dotfiles/blob/master/zsh_profile.d/completion.zsh
+
+_rake_does_task_list_need_generating() {
+ if [[ ! -f .rake_tasks ]]; then return 0;
+ else
+ accurate=$(stat -f%m .rake_tasks)
+ changed=$(stat -f%m Rakefile)
+ return $(expr $accurate '>=' $changed)
fi
- compadd `cat .rake_tasks~`
-fi
+}
+
+_rake() {
+ if [[ -f Rakefile ]]; then
+ if _rake_does_task_list_need_generating; then
+ rake --silent --tasks | cut -d " " -f 2 | cut -d "[" -f 1 > .rake_tasks
+ fi
+ compadd $(cat .rake_tasks)
+ fi
+}
+compdef _rake rake
+

0 comments on commit d4fe01c

Please sign in to comment.