mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-13 22:02:34 +00:00
feat: Adds logs subcommand to shorten-url. For viewing or removing logs.
This commit is contained in:
27
env/.local/scripts/shorten-url
vendored
27
env/.local/scripts/shorten-url
vendored
@@ -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 <<EOF
|
||||
FIX ME!!!
|
||||
Shorten url utility script.
|
||||
|
||||
USAGE:
|
||||
$THIS <flags> <command>
|
||||
|
||||
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 <command> --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
|
||||
|
||||
25
env/.local/scripts/utils/shorten-url/create
vendored
25
env/.local/scripts/utils/shorten-url/create
vendored
@@ -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 <<EOF
|
||||
$THIS FIX ME!!!
|
||||
Create a shortened url, returns / echo's the generated url.
|
||||
|
||||
USAGE:
|
||||
$THIS <flags> <url>
|
||||
|
||||
FLAGS:
|
||||
-c | --code: Set a custom short-code for the link.
|
||||
-e | --expire <time>: Set the expiration for the link.
|
||||
-t | --tag <tag>: Add tag(s) to the link (can be passed multiple times).
|
||||
-h | --help: Show this help page.
|
||||
|
||||
EXMAPLES:
|
||||
|
||||
Generate a link and set the expiration for 30 days from now:
|
||||
$ $THIS --expire 30 days https://example.com
|
||||
|
||||
Generate a link with multiple tags:
|
||||
$ $THIS --tag consult --tag test https://example.com
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
64
env/.local/scripts/utils/shorten-url/logs
vendored
Executable file
64
env/.local/scripts/utils/shorten-url/logs
vendored
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||
THIS_FILE=${BASH_SOURCE[0]} && export THIS_FILE
|
||||
LOG_LABEL=$(basename "$THIS_FILE")
|
||||
THIS=${THIS:-$LOG_LABEL}
|
||||
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
||||
|
||||
rm_flag="0"
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
View or remove the logs.
|
||||
|
||||
USAGE:
|
||||
$THIS <flags> <command>
|
||||
|
||||
FLAGS:
|
||||
-h | --help: Show this help page.
|
||||
|
||||
COMMAND:
|
||||
show: Show the logs (default).
|
||||
rm | remove: Remove the log file.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# MAIN
|
||||
################################################################################
|
||||
|
||||
source "$SCRIPTS/hypr/logging"
|
||||
setup-logging "$LOG_FILE" "$LOG_LABEL"
|
||||
|
||||
[[ -z ${LOG_DIR:-""} ]] &&
|
||||
log --error "Log directory not set." &&
|
||||
exit 1
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == "rm" ]] || [[ $1 == "remove" ]]; then
|
||||
rm_flag="1"
|
||||
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||
usage && exit 0
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
file="$LOG_DIR/$LOG_FILE"
|
||||
|
||||
[[ ! -f "$file" ]] &&
|
||||
echo "No log file at: '$file'" &&
|
||||
exit 0
|
||||
|
||||
if [[ $rm_flag == "1" ]]; then
|
||||
log --echo "Removing logs..."
|
||||
rm -f "$file"
|
||||
else
|
||||
log "Showing logs"
|
||||
bat "$file"
|
||||
fi
|
||||
Reference in New Issue
Block a user