aboutsummaryrefslogtreecommitdiff
path: root/.config/tmux/left-status.sh
blob: 06ae1a6cb9c5ac285157a79b3b0270e5acf2411b (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
#!/bin/bash

function ip-address() {
    # Loop through the interfaces and check for the interface that is up.
    for file in /sys/class/net/*; do
        iface=$(basename $file);
        read status < $file/operstate;
        [ "$status" == "up" ] && ip addr show $iface | awk '/inet /{printf $2" "}'
    done
}

function memory-usage() {
    if [ "$(which bc)" ]; then
        # Display used, total, and percentage of memory using the free command.
        read used total <<< $(free -m | awk '/Mem/{printf $2" "$3}')
        # Calculate the percentage of memory used with bc.
        percent=$(bc -l <<< "100 * $total / $used")
        # Feed the variables into awk and print the values with formating.
        awk -v u=$used -v t=$total -v p=$percent 'BEGIN {printf "%sMi/%sMi %.1f% ", t, u, p}'
    fi
}

function vpn-connection() {
    # Check for tun0 interface.
    [ -d /sys/class/net/tun0 ] && printf "%s " 'VPN*'
}

function main() {
    # Comment out any function you do not need. 
    ip-address
    memory-usage
    vpn-connection
}

# Calling the main function which will call the other functions.
main