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
#!/bin/sh

# The shitter client.
# Your shitter feed lives in /pub/$USER/shitter.
# The shitter feed is a set of newline seperated files, with the
# Your shitter following list is a newline seperated file, $HOME/.shitter.

user=${USER:?variable undefined}
file="/pub/$user/shitter"

err () {
    printf 'error: %s\n' "$1"
    exit 1
}

help () {
    cat << EOF
shitter: shell twitter
options:
    s(hit)      publish a sheet
    h(elp)      show this help menu
    i(nspect)   look at your feed
    t(ail)      add a user to your feed
    e(xplore)   look at the global feed
EOF
}

shit () {
    printf '%s %s %s\n' "$(date +"%s")" "$user" "$1" >> "$file"
    echo "Shat successfully!"
}

inspect () {
    [ -s "$HOME/.shitter" ] || err "Not following any users."
    cat "$HOME/.shitter" | while read -r line; do
        cat "/pub/$line/shitter"
    done | sort -nr | cut -f2- -d ' ' | "${PAGER:-less}"
}

tail () {
    [ -f "/pub/$1/shitter" ] || err "$1 doesn't have a shitter feed."
    echo "$1" >> "$HOME/.shitter"
    echo "$1 followed successfully!"
}

explore () {
    for i in /pub/*/shitter; do
        cat "$i"
    done | sort -nr | cut -f2- -d ' ' | "${PAGER:-less}"
}

main () {
    opt=$1
    shift 1

    case $opt in
        s|shit) shit "$@" ;;
        h|help) help      ;;
        i|inspect) inspect "$@" ;;
        t|tail) tail "$@" ;;
        e|explore) explore "$@" ;;
        *) echo "Option $opt not found" && help ;;
    esac
}

main "$@"