summaryrefslogtreecommitdiffstats
path: root/.local/bin
diff options
context:
space:
mode:
authorNicholas Gorden <ngorden1997@gmail.com>2025-03-05 14:01:04 +0000
committerGitHub <noreply@github.com>2025-03-05 14:01:04 +0000
commit1e750084e5194375002433e3aee554814beef4c1 (patch)
tree0a341cdca25c3fcb2c50c4d6f087e2e34550f243 /.local/bin
parent51baf2e6b33240caf22252443262efa5e24a400e (diff)
downloadeibhear-1e750084e5194375002433e3aee554814beef4c1.tar.gz
eibhear-1e750084e5194375002433e3aee554814beef4c1.tar.zst
eibhear-1e750084e5194375002433e3aee554814beef4c1.zip
New: create sb-ticker (#1436)
* weath: Add option to get forecast from a different location (#1327) * weath: Add option to get forecast from a different location * Remove retry and make max time lower because it is interactive * Give weath 'cp' option to copy forecast as plain text for sharing * Make weath a separate script * shortcuts: export env vars for each shortcut (#1395) useful if want to use shortcuts w/ different progs instead of their default behavior (cd / $EDITOR), e.g.: ```sh cd ~/Downloads mv foo.mp3 $music ``` Co-authored-by: Luke Smith <luke@lukesmith.xyz> * Update mpd to use PipeWire (#1412) per https://wiki.archlinux.org/title/Music_Player_Daemon#Audio_configuration * New: create sb-ticker --------- Co-authored-by: appeasementPolitik <108810900+appeasementPolitik@users.noreply.github.com> Co-authored-by: Kipras Melnikovas <kipras@kipras.org> Co-authored-by: Luke Smith <luke@lukesmith.xyz> Co-authored-by: fennomaani <160141733+fennomaani@users.noreply.github.com>
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/statusbar/sb-ticker50
1 files changed, 50 insertions, 0 deletions
diff --git a/.local/bin/statusbar/sb-ticker b/.local/bin/statusbar/sb-ticker
new file mode 100755
index 0000000..4042a3d
--- /dev/null
+++ b/.local/bin/statusbar/sb-ticker
@@ -0,0 +1,50 @@
+#!/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="$(cat "$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" | grep -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" ;;
+ 2) notify-send -u low "Updating..." "Updating prices" ; updateme="1" ;;
+ 3) notify-send "Current prices:" "Current stock prices:\n<b>$(getchange)</b>
+
+LEFT MOUSE BUTTON: show price file
+MIDDLE MOUSE BUTTON: update stock prices
+RIGHT MOUSE BUTTON: Get stock overview" ;;
+ 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
+esac
+
+[ -n "$updateme" ] && updateprice
+
+[ -f "$pricefile" ] && getchange
+
+checkprice && updateprice