srech.sh 822 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. conent_dir=~/.vim/bundle/self_vim/content.txt
  3. rm -rf $content_dir
  4. sou=$(whiptail --title "search content" --inputbox "input search content" 10 60 "" 3>&1 1>&2 2>&3)
  5. dir=$(whiptail --title "search directory" --inputbox "directory" 10 60 "/" 3>&1 1>&2 2>&3)
  6. for i in `find $dir -type f -name "*"`
  7. do
  8. if [ ${i} != $content_dir ];then
  9. # echo "1-2"|awk 'BEGIN{FS="-";OFS=","}{print $1,$2}
  10. echo "search directory ---" $i
  11. echo `grep -n ${sou} $i|awk -F ':' -v k=$i '{print k}'|sed 's/ /\n/g'|sort |uniq -c` >> $content_dir
  12. fi
  13. done
  14. R=`cat $content_dir|awk '{print $2,$1}'`
  15. if [ -z $R ];then
  16. echo "file not exist"
  17. exit
  18. fi
  19. O=$(whiptail --title "search result" --menu "select open" 15 60 0 $R 3>&1 1>&2 2>&3)
  20. index=`grep "$O" $content_dir|awk '{print $1}'`
  21. echo "open file $O index"
  22. vim $O -c $index