From 76f121236cbf17821362d09eefdee6e0771f0a91 Mon Sep 17 00:00:00 2001 From: "jakob.stendahl" Date: Wed, 17 Apr 2024 12:33:21 +0200 Subject: Add some convenient scripts for pinging me --- bin/pingme.m4 | 15 ++++++++ bin/sqlwait | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/toggle-theme | 21 ++--------- 3 files changed, 132 insertions(+), 17 deletions(-) create mode 100644 bin/pingme.m4 create mode 100755 bin/sqlwait (limited to 'bin') diff --git a/bin/pingme.m4 b/bin/pingme.m4 new file mode 100644 index 0000000..5eea292 --- /dev/null +++ b/bin/pingme.m4 @@ -0,0 +1,15 @@ +#!/bin/sh +set -e +m4_ifelse(DT_GOTIFY_URL, `', `', `m4_dnl +GOTIFY_URL="DT_GOTIFY_URL/message?token=DT_GOTIFY_TOKEN" +')m4_dnl +MESSAGE="Done" +if [ "$#" = "1" ]; then + MESSAGE="$1" +fi + +tput bel +tmux display-message "${MESSAGE}" +m4_ifelse(DT_GOTIFY_URL, `', `', `m4_dnl +GOTIFY_RES=$(curl "$GOTIFY_URL" -F "title=Pingme" -F "message=$MESSAGE" -F "priority=5" 2> /dev/null) +')m4_dnl diff --git a/bin/sqlwait b/bin/sqlwait new file mode 100755 index 0000000..6ba406e --- /dev/null +++ b/bin/sqlwait @@ -0,0 +1,113 @@ +#!/bin/sh +set -e + +PRINT_FLAG=false +MYSQL_HOST="localhost" +COMPARE_TYPE="eq" + +usage() { + printf "$0 [options] \n" + printf "\t-H \tMysql host\n" + printf "\t-u \tMysql user\n" + printf "\t-d \tMysql database\n" + printf "\t-c \teq, lt or gt, defaults to eq\n" + printf "\t-p\t\tPrint the current value for each check\n" +} + + +while getopts "H:u:d:c:p" opt; do + case ${opt} in + H ) + MYSQL_HOST="$OPTARG" + ;; + u ) + MYSQL_USER="$OPTARG" + ;; + d ) + MYSQL_DATABASE="$OPTARG" + ;; + c ) + COMPARE_TYPE="$OPTARG" + ;; + p ) + PRINT_FLAG=true + ;; + \? ) + echo "Invalid option: $OPTARG" 1>&2 + exit 1 + ;; + : ) + echo "Option -$OPTARG requires an argument." 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND -1)) + +if [ -z "$1" ]; then + echo "Error: argument is missing." >&2 + usage + exit 1 +fi +QUERY="$1" + +if [ -z "$2" ]; then + echo "Error: argument is missing." >&2 + usage + exit 1 +fi +TARGET="$2" + +if [ -z "$MYSQL_HOST" ]; then + echo "Error: -H argument is missing." >&2 + usage + exit 1 +fi + +if [ -z "$MYSQL_USER" ]; then + echo "Error: -u argument is missing." >&2 + usage + exit 1 +fi + +if [ -z "$MYSQL_DATABASE" ]; then + echo "Error: -d argument is missing." >&2 + usage + exit 1 +fi + +read -s -p "Enter password: " MYSQL_PASSWORD +echo + +while true; do + RESULT=$(mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -h"$MYSQL_HOST" "$MYSQL_DATABASE" -e "$QUERY" --batch --silent 2> /dev/null) + if [ "$PRINT_FLAG" = true ]; then + echo "[$(date)]: ${RESULT}" + fi + + if [ "$COMPARE_TYPE" = "eq" ]; then + if [ "$RESULT" = "$$TARGET" ]; then + if [ "$PRINT_FLAG" = true ]; then + echo "[$(date)]: Target reached $RESULT = $TARGET" + fi + break + fi + elif [ "$COMPARE_TYPE" = "lt" ]; then + if (( RESULT < TARGET )); then + if [ "$PRINT_FLAG" = true ]; then + echo "[$(date)]: Target reached $RESULT < $TARGET" + fi + break + fi + elif [ "$COMPARE_TYPE" = "gt" ]; then + if (( RESULT > TARGET )); then + if [ "$PRINT_FLAG" = true ]; then + echo "[$(date)]: Target reached $RESULT > $TARGET" + fi + break + fi + fi + + sleep 10 +done + diff --git a/bin/toggle-theme b/bin/toggle-theme index aa3c626..8fe1547 100755 --- a/bin/toggle-theme +++ b/bin/toggle-theme @@ -27,14 +27,8 @@ if [ "$THEME" = "dark" ]; then # Update tmux (Consider making a theme switch in the m4 config and re-running that instead of having it configured here) tmux set-environment THEME "light" tmux set-environment ALACRITTY_THEME "${LIGHTTHEME}" - tmux set -g status-bg "#F2EEDE" - tmux set -g status-fg colour15 - tmux setw -g window-status-current-style "bg=colour0,fg=colour255" - tmux setw -g window-status-style "bg=colour7,fg=colour0" - tmux setw -g window-status-bell-style "bg=colour23,fg=colour255" - tmux setw -g window-status-activity-style "bg=colour243,fg=colour255" - tmux set -g status-left "#[fg=colour232,bg=colour3,bold]#{?client_prefix,C-a,}#[default] #[fg=colour0,bg=colour7,bold][#S]#[default] " - tmux set -g status-right "#[fg=colour0,bg=colour7,bold] #(hostname) #[default] #[fg=colour0,bg=colour7,bold] %d/%m/%y #[default] #[fg=colour0,bg=colour7,bold] %H:%M:%S #[default] #[bg=colour7,fg=colour0,bold] #(cat /sys/class/power_supply/BAT0/capacity)% #[default] " + tmux set -g status-bg black + tmux set -g status-fg colour255 # Update nvim send_vim_cmd ":set background=light" @@ -49,15 +43,8 @@ else # Update tmux tmux set-environment THEME "dark" tmux set-environment ALACRITTY_THEME "${DARKTHEME}" - tmux set -g status-bg "#0c0c0c" - tmux set -g status-fg "#d6d6d6" - tmux setw -g window-status-style "bg=colour235,fg=colour7" - tmux setw -g window-status-current-style "bg=colour237,fg=colour7" - tmux setw -g window-status-bell-style "bg=colour23,fg=colour15" - tmux setw -g window-status-activity-style "bg=colour239,fg=colour15" - tmux set -g status-left "#[fg=colour232,bg=colour3,bold]#{?client_prefix,C-a,}#[default] #[fg=colour7,bg=colour235,bold][#S]#[default] " - tmux set -g status-right "#[fg=colour7,bg=colour235,bold] #(hostname) #[default] #[fg=colour7,bg=colour235,bold] %d/%m/%y #[default] #[fg=colour7,bg=colour235,bold] %H:%M:%S #[default] #[bg=colour235,fg=colour7,bold] #(cat /sys/class/power_supply/BAT0/capacity)% #[default] " - sed -i 's/"dark"/"light"/' "${VIMCONF}" + tmux set -g status-bg white + tmux set -g status-fg black # Update nvim send_vim_cmd ":set background=dark" -- cgit v1.2.3