Advertisement
Guest User

variety-loop

a guest
Feb 13th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.84 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. (( $# )) && echo arguments are ignored
  4. echo 'Useage: variety -<input>
  5.  --* -> read more then 1 char
  6.  -q  -> --quit  (Also quits from ^D)
  7.  -n  -> --next
  8.  -p  -> --previous
  9.  -t  -> --trash
  10.  -f  -> --favorite
  11. '
  12. # trap KILL?  'variety -q'   ?todo?
  13. { pidof variety || variety --pause; } &>/dev/null & # in case if is not running
  14. eof=$'\4' # end of input ( Ctrl+D = ^D )
  15. er(){ printf "\\E[10Cvariety err code: $?\\E[28D\\E[${#?}D"; }
  16.  
  17. while IFS= read -p 'variety -' -n 1 i; do  case $i in
  18.     [nptf]) { variety -"$i" &>/dev/null || er; } &;;
  19.     -|["\'\""]) read j || break; eval "variety -$i$j || er";;
  20.  
  21.     q|"$eof") break;;
  22.     [$'\E\t ']|'') read -t 0.1 -s -p $'\r                  \r' _; continue;; # ignore arow + special keys
  23.     *) printf '\n  invalid option: %s' "${i@Q}";;
  24. esac; echo;  done
  25. echo
  26.  
  27. variety --quit &>/dev/null
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement