-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmscr
executable file
·79 lines (65 loc) · 2.54 KB
/
mscr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
# shellcheck disable=1090,2154,2086
ping -c 1 stonks.icu >/dev/null || exit 1
STONK_LIST="${XDG_CONFIG_HOME-$HOME/.config}/i3blocks/mscr"
. "${XDG_CACHE_HOME-$HOME/.cache}/wal/colors.sh"
label=
blockcolor=$color7
txtcolor=$color8
# FIXME: stonks seems to encounter a bug once in a while where it will not
# exit correctly and loop forever
# if command -v stonks >/dev/null; then
stonk_getter="stonks $(head -1 "$STONK_LIST")"
# else
# stonk_getter="curl --no-progress-meter "https://stonks.icu/$(head -1 "$STONK_LIST")""
# fi
case $BLOCK_BUTTON in
1) # Left Click
$TERMINAL --class float --hold -e $stonk_getter
;;
2) # Middle Click
$TERMINAL --class float -e nvim "$STONK_LIST"
;;
3) # Right Click
notify-send "STOCKS BEING WATCHED" "$(cat "$STONK_LIST")"
;;
# Navigate through the user-defined stocks by scrolling
4) # Scroll Up
moved_ticker=$(head -1 "$STONK_LIST")
other_tickers=$(tail -n +2 "$STONK_LIST")
echo "$other_tickers" > "$STONK_LIST"
echo "$moved_ticker" >> "$STONK_LIST"
;;
5) # Scroll Down
next_ticker=$(tail -1 "$STONK_LIST")
other_tickers=$(head -n -1 "$STONK_LIST")
echo "$next_ticker" > "$STONK_LIST"
echo "$other_tickers" >> "$STONK_LIST"
;;
esac
current_ticker=$(head -1 "$STONK_LIST")
# if command -v stonks >/dev/null; then
stonk_getter(){ stonks $current_ticker ;}
# else
# stonk_getter(){ curl --no-progress-meter https://stonks.icu/$current_ticker ;}
# fi
stonk_info=$(stonk_getter | sed -n 2p | tr '|' '\n' | tr '(' '\n' |
tr ')' '\n' | sed 's/┃//')
stonk_name=$(echo "$stonk_info" | sed -n 1p | awk '{$1="";print}')
stonk_price=$(echo "$stonk_info" | sed -n 2p | awk -Fm '{print $2}')
stonk_delta_percentage=$(echo "$stonk_info" | sed -n 3p | xargs)
# stonk_delta_absolute=$(echo "$stonk_info" | sed -n 4p)
if echo "$stonk_delta_percentage" | grep -q '-'; then
stonk_price_color="$color9"
else
stonk_price_color="$color10"
stonk_delta_percentage="+$stonk_delta_percentage"
fi
printf "<b><span foreground='%s' background='%s'></span>" $blockcolor $color0
printf "<span foreground='%s' background='%s'> %s(</span>" \
$txtcolor $blockcolor "$label$stonk_name $stonk_price"
printf "<span foreground='%s' background='%s'>%s</span>" \
$stonk_price_color $blockcolor $stonk_delta_percentage
printf "<span foreground='%s' background='%s'>)</span>" $txtcolor $blockcolor
printf "<span foreground='%s' background='%s'></span></b>\n" \
$color0 $blockcolor