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
|
declare -a args
|
||||||
no_spin_flag="0"
|
no_spin_flag="0"
|
||||||
create_flag="0"
|
create_flag="0"
|
||||||
|
logs_flag="0"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
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
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +56,12 @@ create() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logs() {
|
||||||
|
script="$SCRIPTS/utils/shorten-url/logs"
|
||||||
|
export THIS="$THIS logs"
|
||||||
|
source "$script" "${args[*]}"
|
||||||
|
}
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# MAIN
|
# MAIN
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -54,6 +75,8 @@ while [[ $# -gt 0 ]]; do
|
|||||||
no_spin_flag="1"
|
no_spin_flag="1"
|
||||||
elif [[ $1 == "create" ]]; then
|
elif [[ $1 == "create" ]]; then
|
||||||
create_flag="1"
|
create_flag="1"
|
||||||
|
elif [[ $1 == "logs" ]]; then
|
||||||
|
logs_flag="1"
|
||||||
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||||
no_spin_flag="1"
|
no_spin_flag="1"
|
||||||
args+=("$1")
|
args+=("$1")
|
||||||
@@ -65,6 +88,8 @@ done
|
|||||||
|
|
||||||
if [[ $create_flag == "1" ]]; then
|
if [[ $create_flag == "1" ]]; then
|
||||||
create
|
create
|
||||||
|
elif [[ $logs_flag == "1" ]]; then
|
||||||
|
logs
|
||||||
else
|
else
|
||||||
# If we made it here, no subcommands were executed.
|
# If we made it here, no subcommands were executed.
|
||||||
usage
|
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 nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
|
# Global variables.
|
||||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
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")
|
LOG_LABEL=$(basename "$THIS_FILE")
|
||||||
THIS=${THIS:-$LOG_LABEL}
|
THIS=${THIS:-$LOG_LABEL}
|
||||||
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
||||||
|
|
||||||
# Setup environment
|
# Setup environment
|
||||||
source "$SCRIPTS/utils/shorten-url/env"
|
source "$SCRIPTS/utils/shorten-url/env"
|
||||||
|
|
||||||
|
# Local variables.
|
||||||
declare -a tags
|
declare -a tags
|
||||||
url=""
|
url=""
|
||||||
shortCode=""
|
shortCode=""
|
||||||
@@ -20,7 +21,25 @@ expire=""
|
|||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOF
|
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
|
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