summaryrefslogtreecommitdiff
path: root/oldi3status.sh
blob: e1cb415f5ce8b5935f71078faf1a3c321a94f37a (plain) (blame)
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
#!/bin/sh
# Adam's custom i3status script.

# Configuration variables.
ticker_length=5 # Ticker length in words.

# Echo the text the ticker should scroll over. No newlines!
init_ticker() {
    echo $(fortune | tr -d '\b\r\\' | tr -s '\n\t\v\f' ' ' | tr -s '"' "'")
}

# Cut up text for ticker tape.
gen_ticker() {
    echo $(
        echo $text | cut -d' ' -f$word_index-$((
            $word_index + $ticker_length - 1
        ))
    )
}

# Prints out valid JSON for i3status using given parameters.
printer() {
    printf "\"full_text\":\"%s\"," "$1"
    printf "\"align\":\"%s\"," "$2"
    printf "\"min_width\":%d}," $3
}

# Main loop.
i3status | (
    read line && \
    echo "$line" && \
    read line && \
    echo "$line" && \
    read line && \
    echo "$line" && \
    while : 
do
    # Get i3status line.
    read line

    # If ticker text is empty, re-initialize text and word index. Then generate
    # ticker text.
    [[ -z "$ticker_text" ]] && word_index=1 && text=$(init_ticker)
    ticker_text=$(gen_ticker) && ((word_index += 1))

    # Print i3status header string.
    printf ",[{"

    # Print ticker tape JSON.
    printer "$ticker_text" "left" 250

    # Print the rest of the status string.
    echo "${line#,\[}"
    #printf "%s" $line

done)