shorthand.sh 922 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. #eval $(xdotool getdisplaygeometry --shell)
  3. SCRIPT=`realpath $0`
  4. dir=`dirname $SCRIPT`
  5. src=${@:1:1}
  6. opt=${@:2:1}
  7. src=$(ls $dir/$src*.sh)
  8. if [ -z "$opt" ]; then
  9. opts=$(grep "==.*\$opt" $src | grep -v grep | sed 's/[^"]*"//;s/".*//')
  10. echo "Work Options: "$opts
  11. else
  12. #short hand
  13. c=$(echo "$opt" | sed 's/[0-9]//g')
  14. opts=$(grep "==.*\$opt" $src | grep -v grep | sed 's/[^"]*"//;s/".*//')
  15. list=$(echo "$opts" | grep ^$c)
  16. opts=($(echo $list))
  17. count=${#opts[@]}
  18. if [ "2" -gt "$count" ]; then
  19. echo "olv work ${opts[0]} ${@:2}"
  20. else
  21. index=$(echo $opt | sed 's/[^0-9]//g')
  22. if [ -z "$index" ]; then
  23. echo "Options:"
  24. echo "$list" | nl -v0
  25. read -p "olv work $c#: " index
  26. index=$(echo "$index" | sed 's/[^0-9]//g')
  27. if [ -z "$index" ]; then
  28. echo "No option selected."
  29. exit
  30. fi
  31. fi
  32. echo "olv work ${opts[$index]} ${@:2}"
  33. fi
  34. fi