Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Place this command to an arbitrary path e.g. bin/example.bash
- # Grant a permission
- # chmod u+x bin/ex.bash
- # Put a symlink without extension into top of project
- # ln -s bin/ex.bash ./ex
- # Execute the command
- # ./ex init
- # Use environment variable to pass arguments (Might better not to make the script such complicated)
- # FOO_DIR="~/sample_path/" ./ex download
- function ex() {
- set -u
- local SELF="$(basename $0)"
- local NAME="Example Command Desctiption"
- local UTIME="$(date +'%Y%m%d')"
- local WORK_DIR="$(pwd)"
- local PID_PATH="${WORK_DIR}/var/.pids"
- init() {
- echo "Do some initializations here"
- }
- __show-message() {
- echo "This method doesn't show up in usage if you put a prefix __ (double underscore)"
- }
- logs() {
- tail -F logs/*.log
- }
- download() {
- rsync -avzP --bwlimit=8000 example.com:/path/ ${FOO_DIR:=${WORK_DIR}}
- }
- usage() {
- echo -e "${SELF} -- ${NAME}\nUsage: ${SELF} [sub-command]\n[Sub-commands]:"
- declare -F | awk '{print "\t" $3}' | grep -v ${SELF} | grep -vE '^\t__[^_]+'
- }
- if [[ $# = 0 ]]; then
- usage
- echo "INFO: ${SELF} requires a sub-command"
- elif [[ "$(type -t $1)" = "function" ]]; then
- $1
- else
- usage
- fi
- }
- ex $1
Add Comment
Please, Sign In to add comment