diff --git a/env/.local/scripts/shorten-url b/env/.local/scripts/shorten-url index 3ae33b4..bc19824 100755 --- a/env/.local/scripts/shorten-url +++ b/env/.local/scripts/shorten-url @@ -15,10 +15,25 @@ LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"} && export LOG_FILE declare -a args no_spin_flag="0" create_flag="0" +logs_flag="0" usage() { cat < + +FLAGS: + --no-spin: Disable spinners for commands. + -h | --help: Show this help page. + +COMMANDS: + create: Create a new shortened url. + logs: View or remove the logs. + +Run '$THIS --help' for more information on a command. + EOF } @@ -41,6 +56,12 @@ create() { fi } +logs() { + script="$SCRIPTS/utils/shorten-url/logs" + export THIS="$THIS logs" + source "$script" "${args[*]}" +} + ################################################################################ # MAIN ################################################################################ @@ -54,6 +75,8 @@ while [[ $# -gt 0 ]]; do no_spin_flag="1" elif [[ $1 == "create" ]]; then create_flag="1" + elif [[ $1 == "logs" ]]; then + logs_flag="1" elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then no_spin_flag="1" args+=("$1") @@ -65,6 +88,8 @@ done if [[ $create_flag == "1" ]]; then create +elif [[ $logs_flag == "1" ]]; then + logs else # If we made it here, no subcommands were executed. usage diff --git a/env/.local/scripts/utils/shorten-url/create b/env/.local/scripts/utils/shorten-url/create index 5a5e3a6..8346010 100755 --- a/env/.local/scripts/utils/shorten-url/create +++ b/env/.local/scripts/utils/shorten-url/create @@ -4,15 +4,16 @@ set -e set -o nounset set -o pipefail +# Global variables. SCRIPTS=${SCRIPTS:-$HOME/.local/scripts} -THIS_FILE=${BASH_SOURCE[0]} && export THIS_FILE +THIS_FILE=${BASH_SOURCE[0]} && export THIS_FILE # Export for log function to work properly. LOG_LABEL=$(basename "$THIS_FILE") THIS=${THIS:-$LOG_LABEL} LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"} - # Setup environment source "$SCRIPTS/utils/shorten-url/env" +# Local variables. declare -a tags url="" shortCode="" @@ -20,7 +21,25 @@ expire="" usage() { cat < + +FLAGS: + -c | --code: Set a custom short-code for the link. + -e | --expire