init.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. SCRIPT=`realpath $0`
  3. olv=`dirname $SCRIPT`
  4. cmd=${@:1:1}
  5. if [ -z "$cmd" ]; then
  6. opts=$(ls $olv/*.sh | sed 's/.*\///;s/\.sh//')
  7. echo "Olv Options: "$opts
  8. else
  9. if [ "init" == "$cmd" ]; then
  10. cmd=${@:2:1}
  11. if [ -z "$cmd" ]; then
  12. #echo "You wanted me to init something?";
  13. opts=$(ls $olv/init/*.sh | sed 's/.*\///;s/\.sh//')
  14. echo "Init Options: "$opts
  15. exit
  16. fi
  17. if [ -f "$olv/init/$cmd.sh" ]; then
  18. $olv/init/$cmd.sh ${@:3}
  19. else
  20. cmd=$(ls $olv/init | grep -i $cmd | grep -v \~ | head -1)
  21. if [ -f "$olv/init/$cmd" ]; then
  22. $olv/init/$cmd ${@:3}
  23. fi
  24. fi
  25. elif [ "i" == "$cmd" ]; then
  26. while :; do
  27. read -p "[olv]: " action
  28. olv $action
  29. done
  30. else
  31. if [ -f "$olv/$cmd.sh" ]; then
  32. $olv/$cmd.sh ${@:2}
  33. else
  34. #short hand with spaces
  35. c=$(echo "$cmd" | sed 's/[0-9]//g')
  36. list=$(ls $olv | grep ^$c.*\.sh$ | sed 's/.*\///;s/\.sh//')
  37. if [ -z "$list" ]; then
  38. #shorthand w/o spaces
  39. list=$(ls $olv | grep ^${c:0:1}.*\.sh$ | sed 's/.*\///;s/\.sh//')
  40. if [ ! -z "$list" ]; then
  41. cmd=$(echo "$cmd" | sed 's/\([^a-zA-Z]*\)/\1 /g')
  42. olv ${cmd:1} ${@:2}
  43. exit
  44. fi
  45. fi
  46. cmds=($(echo "$list"))
  47. count=${#cmds[@]}
  48. if [ "2" -gt "$count" ]; then
  49. olv ${cmds[0]} ${@:2}
  50. else
  51. index=$(echo ${@:1:1} | sed 's/[^0-9]//g')
  52. if [ -z "$index" ]; then
  53. echo "Options:"
  54. echo "$list" | nl -v0
  55. read -p "olv $c#: " index
  56. index=$(echo "$index" | sed 's/[^0-9]//g')
  57. if [ -z "$index" ]; then
  58. echo "No option selected."
  59. exit
  60. fi
  61. fi
  62. olv ${cmds[$index]} ${@:2}
  63. fi
  64. fi
  65. fi
  66. fi