OSDN Git Service

Merge pull request #80 from instantOS/nocase_keysearch
[instantos/instantOS.git] / programs / instantspeedtest
1 #!/bin/bash
2
3 instantinstall speedtest-cli || exit 1
4
5 imenu -w "running speedtest, please wait" &
6 SPEEDOUT="$(speedtest-cli --simple)"
7 pkill instantmenu
8
9 if [ -z "$SPEEDOUT" ]; then
10     echo 'running the speedtest failed
11 are you connected to the internet?' | imenu -M
12     exit 1
13 fi
14
15
16 PING="$(sed -n '1p' <<<"$SPEEDOUT" | grep -o '[0-9].*')"
17 DOWNLOAD="$(sed -n '2p' <<<"$SPEEDOUT" | grep -o '[0-9].*')"
18 UPLOAD="$(sed -n '3p' <<<"$SPEEDOUT" | grep -o '[0-9].*')"
19
20 [ -e ~/.cache/instantos/speedtest ] || touch ~/.cache/instantos/speedtest
21 sed -i "1i$(date '+%Y.%m.%d.%H.%M'):$PING:$DOWNLOAD:$UPLOAD" ~/.cache/instantos/speedtest
22 sed -i '400,$d' ~/.cache/instantos/speedtest
23
24 while :; do
25     CHOICE="$(
26         {
27             echo ":b ﴽ$PING"
28             echo ":b $DOWNLOAD"
29             echo ":b $UPLOAD"
30             echo ":b Copy all"
31             echo "OK"
32         } | instantmenu -l 20 -c -h -1 -wm -w -1 -q 'speedtest'
33     )"
34
35     [ -z "$CHOICE" ] && exit 1
36
37     if [ "$CHOICE" = "OK" ]; then
38         exit
39     fi
40
41     if grep -q 'ﴽ' <<<"$CHOICE"; then
42         COPIER="$PING"
43     elif grep -q '' <<<"$CHOICE"; then
44         COPIER="$DOWNLOAD"
45     elif grep -q '' <<<"$CHOICE"; then
46         COPIER="$UPLOAD"
47     elif grep -q '' <<<"$CHOICE"; then
48         COPIER="$PING
49 Download: $DOWNLOAD
50 Upload: $UPLOAD"
51     fi
52
53     [ -n "$COPIER" ] && echo "$COPIER" | xclip -selection c && notify-send "copied $COPIER to clipboard"
54
55 done