Advertisement
metalx1000

BASH List Highlighter and Selector

Jan 8th, 2018
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.86 KB | None | 0 0
  1. #!/bin/bash
  2. #description     :selectable list with high lighting
  3. #usage           : used 'w' and 's' to move up and down
  4. #                : 'e' to select and 'q' to quit
  5. #author          :Kris Occhipinti https://filmsbykris.com
  6. #date            :  Jan 8th 2018
  7. #license         :GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt
  8.  
  9. let x=0;
  10.  
  11. list=("BOB" "TIM" "TED" "BILL" "FRANK" "KELLY");
  12. length=${#list[@]}
  13.  
  14. while [ 1 ]
  15. do
  16.   clear
  17.   for (( i=0; i<$length;i++ ));
  18.   do
  19.     if [ $i = $x ]
  20.     then
  21.       echo -e "\e[7m${list[$i]}\e[0m"
  22.     else
  23.       echo "${list[$i]}"
  24.     fi
  25.   done
  26.  
  27.   read -rsn1 k
  28.  
  29.   case $k in
  30.     "s") let x++;;
  31.     "w") let x--;;
  32.     "q") echo "Goodbye...";exit 0;;
  33.     "e") echo "${list[$x]} was selected.";sleep 1;echo "GoodBye...";exit 0;;
  34.   esac
  35.  
  36.   if [ $x -lt 0 ]
  37.   then
  38.     let x=0;
  39.   elif [ $x -ge $length ]
  40.   then
  41.    let x=$length-1;
  42.   fi
  43.  
  44. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement