summaryrefslogtreecommitdiff
path: root/.local/bin/barpos
blob: 6caf44d8abf3dd789e63189c6471f2359ea08dc1 (plain)
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
#!/bin/bash

BAR_CFG=$XDG_CONFIG_HOME/polybar/config.ini 

BOTTOM="bottom = true"
TOP="bottom = false"

main () {
    if [ ! -n "$1" ]; then
        toggle
    fi

    while [ -n "$1" ]; do # while loop starts
        case "$1" in
            -b) 
                bottom; break ;;
            -t) 
                top; break ;;
            -h|--help)
                help ; break ;;
            *) 
                usage; echo "error: unrecognized arguments: $1" ; exit 1 ;;
        esac
        shift
    done
}

usage () {
    echo "usage: barpos [options]"
}

help () {
    usage
    echo
    echo "Toggles status bar position, or sets it as specified"
    echo
    echo "options:"
    echo "  -h, --help            show this help message and exit"
    echo "  -b                    bottom"
    echo "  -t                    top"
}

toggle () {
    if grep -Eq "^$BOTTOM$" $BAR_CFG; then
        top
    else
        bottom
    fi
}

bottom () {
    sed -ir "s|^bottom = .*$|bottom = true|" $BAR_CFG
}

top () {
    sed -ir "s|^bottom = .*$|bottom = false|" $BAR_CFG
}

main "$@"