Advertisement
metalx1000

BASH filter list while typing

Apr 27th, 2018
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.76 KB | None | 0 0
  1. #!/bin/bash
  2. #Copyright Kris Occhipinti 2018
  3. #http://filmsbykris.com
  4. #license GPLv3 - https://www.gnu.org/licenses/gpl.txt
  5.  
  6. l=$(ls *.jpg)
  7. tmp_i=""
  8. i=""
  9. viewer="feh"
  10.  
  11. clear
  12. echo "$l"
  13.  
  14. function prompt(){
  15.   clear
  16.   output="$(echo "$l"|grep -i "$i")"
  17.   count="$(echo "$l"|grep -i "$i"|wc -l)"
  18.  
  19.   echo "$count results for $i"
  20.   echo "===================================="
  21.   echo "$output"
  22.  
  23. }
  24.  
  25. while true; do
  26. read -rsn1 input
  27.   i+=$input
  28.   prompt
  29.  
  30.   if [ "$output" == "" ]
  31.   then
  32.     echo "No Entries Found for ${i}..."
  33.     echo "Clearing list"
  34.     i="$tmp_i";
  35.     sleep 1
  36.     prompt
  37.   elif [ $count -eq 1 ]
  38.   then
  39.     clear
  40.     echo "$output is found"
  41.     $viewer "$output"
  42.     i=""
  43.     prompt
  44.     #break
  45.   fi
  46.   tmp_i="$i"
  47.  
  48. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement