aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/statusbar/sb-ticker
diff options
context:
space:
mode:
authorawy <awy@awy.one>2025-07-29 03:42:18 +0300
committerawy <awy@awy.one>2025-07-29 03:42:18 +0300
commitef6dff4cce15186a66ba34cdd7bd39958ebf7f58 (patch)
treefcfa61164ca6e79c900b5d11f6afc6b46aaccb84 /.local/bin/statusbar/sb-ticker
downloadhyprdots-ef6dff4cce15186a66ba34cdd7bd39958ebf7f58.tar.gz
first commit
Diffstat (limited to '.local/bin/statusbar/sb-ticker')
-rwxr-xr-x.local/bin/statusbar/sb-ticker49
1 files changed, 49 insertions, 0 deletions
diff --git a/.local/bin/statusbar/sb-ticker b/.local/bin/statusbar/sb-ticker
new file mode 100755
index 0000000..5b26160
--- /dev/null
+++ b/.local/bin/statusbar/sb-ticker
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+# Usage
+# sb-ticker
+# Sample output
+# ^DJI: 0.09%
+# CL=F: -1.88%
+# Description
+# displays/retrieves the latest percent-change in stock market quotes listed in $XDG_CONFIG_HOME/tickers.
+# defaults to S&P 500, Dow Jones Industrial, and the Nasdaq
+#
+# intended to be used in the statusbar, which will display the first quote price in the output
+
+url="terminal-stocks.dev"
+pricefile="${XDG_CACHE_HOME:-$HOME/.cache}/stock-prices"
+tickerfile="${XDG_CONFIG_HOME:-$HOME/.config}/tickers"
+
+[ -f "$tickerfile" ] && tickers="$(bat "$tickerfile")" || tickers="^GSPC,^DJI,^IXIC";
+
+checkprice() {
+ [ -s "$pricefile" ] && [ "$(stat -c %y "$pricefile" 2>/dev/null |
+ cut -d':' -f1)" != "$(date '+%Y-%m-%d %H')" ]
+}
+
+getchange() {
+ mapfile -t changes < <(sed -e 's/ / /g' "$pricefile" | rg -oe '[m-]\+[0-9]\+\.[0-9]\+' | sed 's/[m ]/;/g')
+ IFS=',' read -ra TICKER <<< "$tickers"
+ for idx in "${!TICKER[@]}"; do
+ printf "%s: %s%%\n" "${TICKER[$idx]}" "${changes[$idx]//;/}"
+ done
+}
+
+updateprice() { curl -sfm 10 "$url/$tickers" --output "$pricefile" || rm -f "$pricefile" ; }
+
+case $BLOCK_BUTTON in
+ 1) setsid "$TERMINAL" -e less -Srf "$pricefile" >/dev/null 2>&1 ;;
+ 2) notify-send -u low "Updating..." "Updating prices" ; updateme="1" ;;
+ 3) notify-send "Current prices:" "Current stock prices:\n<b>$(getchange)</b>
+- Left click to show price file
+- Middle click to update stock prices
+- Right click to get stock overview" ;;
+ 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" >/dev/null 2>&1 ;;
+esac
+
+[ -n "$updateme" ] && updateprice
+
+[ -f "$pricefile" ] && getchange
+
+checkprice && updateprice