aboutsummaryrefslogtreecommitdiff
path: root/.config/tmux/left-status.sh
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2022-12-03 22:29:59 +0200
committersrdusr <trevorgray@srdusr.com>2022-12-03 22:29:59 +0200
commit8fd117c5413985f0c77440a3aff2ce830d78dae2 (patch)
treedd64067842c8086fcf5bbd7de15e392e1692e420 /.config/tmux/left-status.sh
parentff66c93966c3be1ef67d1a06335a5c36eb587bf3 (diff)
downloaddotfiles-8fd117c5413985f0c77440a3aff2ce830d78dae2.tar.gz
dotfiles-8fd117c5413985f0c77440a3aff2ce830d78dae2.zip
Add left-status script to show ip address, memory usage and if connected to a vpn
Diffstat (limited to '.config/tmux/left-status.sh')
-rwxr-xr-x.config/tmux/left-status.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/.config/tmux/left-status.sh b/.config/tmux/left-status.sh
new file mode 100755
index 0000000..06ae1a6
--- /dev/null
+++ b/.config/tmux/left-status.sh
@@ -0,0 +1,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