Guest User

Untitled

a guest
Jan 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # Place this command to an arbitrary path e.g. bin/example.bash
  4. # Grant a permission
  5. # chmod u+x bin/ex.bash
  6. # Put a symlink without extension into top of project
  7. # ln -s bin/ex.bash ./ex
  8. # Execute the command
  9. # ./ex init
  10. # Use environment variable to pass arguments (Might better not to make the script such complicated)
  11. # FOO_DIR="~/sample_path/" ./ex download
  12.  
  13. function ex() {
  14. set -u
  15. local SELF="$(basename $0)"
  16. local NAME="Example Command Desctiption"
  17. local UTIME="$(date +'%Y%m%d')"
  18. local WORK_DIR="$(pwd)"
  19. local PID_PATH="${WORK_DIR}/var/.pids"
  20.  
  21. init() {
  22. echo "Do some initializations here"
  23. }
  24.  
  25. __show-message() {
  26. echo "This method doesn't show up in usage if you put a prefix __ (double underscore)"
  27. }
  28.  
  29. logs() {
  30. tail -F logs/*.log
  31. }
  32.  
  33. download() {
  34. rsync -avzP --bwlimit=8000 example.com:/path/ ${FOO_DIR:=${WORK_DIR}}
  35. }
  36.  
  37. usage() {
  38. echo -e "${SELF} -- ${NAME}\nUsage: ${SELF} [sub-command]\n[Sub-commands]:"
  39. declare -F | awk '{print "\t" $3}' | grep -v ${SELF} | grep -vE '^\t__[^_]+'
  40. }
  41.  
  42. if [[ $# = 0 ]]; then
  43. usage
  44. echo "INFO: ${SELF} requires a sub-command"
  45. elif [[ "$(type -t $1)" = "function" ]]; then
  46. $1
  47. else
  48. usage
  49. fi
  50. }
  51.  
  52. ex $1
Add Comment
Please, Sign In to add comment