]> www.git.dmfe.net Git - dotfiles/commitdiff
i3blocks scripts total rework. Add shell init scripts for vault and kubectl.
authorDmitry Fedotov <dm.fe@yandex.ru>
Wed, 8 Jul 2020 12:17:15 +0000 (15:17 +0300)
committerDmitry Fedotov <dm.fe@yandex.ru>
Wed, 8 Jul 2020 12:17:15 +0000 (15:17 +0300)
15 files changed:
scripts/cpu-temp.sh
scripts/cpu-util.sh [new file with mode: 0755]
scripts/date-time.sh [new file with mode: 0755]
scripts/disk.sh [new file with mode: 0755]
scripts/i3b-formatter.sh [new file with mode: 0755]
scripts/i3mpd.sh
scripts/iface.sh
scripts/key-map.sh [deleted file]
scripts/keymap-switch.sh
scripts/mem.sh
scripts/nettraf.sh [new file with mode: 0755]
scripts/volume.sh
shell/init_scripts/bashrc.mrc
shell/init_scripts/kube.mrc [new file with mode: 0644]
shell/init_scripts/vault.mrc [new file with mode: 0644]

index 4ffbcd9493db99e4cd97ae787a7c1def9b4a61af..02225b62e7f8e3c90b5c2bf337affe6784aa478c 100755 (executable)
@@ -1,3 +1,12 @@
 #!/bin/sh
 
-sensors | awk '/^k10temp/ {getline; getline; print $2}'
+case $BLOCK_BUTTON in
+    2)
+        nohup "${TERMINAL}" -e "${EDITOR}" "$0" >/dev/null &
+        ;;
+esac
+
+temp="$(sensors | awk '/^k10temp/ {getline; getline; print $2}')"
+icon=""
+
+printf "%s %s\n" "${icon}" "${temp}"
diff --git a/scripts/cpu-util.sh b/scripts/cpu-util.sh
new file mode 100755 (executable)
index 0000000..d93546f
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+case ${BLOCK_BUTTON} in
+    2)
+        nohup "${TERMINAL}" -e "${EDITOR}" "$0" >/dev/null &
+        ;;
+esac
+
+logfile="${HOME}/.cache/cpulog"
+prevdata="$(cat ${logfile})"
+curdata="$(grep 'cpu ' /proc/stat | awk '{print $2" "$4" "$5}')"
+
+puser="$(echo ${prevdata} | cut -d' ' -f1)"
+psystem="$(echo ${prevdata} | cut -d' ' -f2)"
+pidle="$(echo ${prevdata} | cut -d' ' -f3)"
+
+cuser="$(echo ${curdata} | cut -d' ' -f1)"
+csystem="$(echo ${curdata} | cut -d' ' -f2)"
+cidle="$(echo ${curdata} | cut -d' ' -f3)"
+
+work="$(((cuser+csystem)-(puser+psystem)))"
+idle="$((cidle-pidle))"
+
+cpu="$((100*work/(work+idle)))"
+
+echo "${curdata}" > "${logfile}"
+
+icon=""
+
+printf "%s %.f%%\n" "${icon}" "${cpu}"
diff --git a/scripts/date-time.sh b/scripts/date-time.sh
new file mode 100755 (executable)
index 0000000..7303dd4
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+case ${BLOCK_BUTTON} in
+    1)
+        nohup "${TERMINAL}" -e sh -c 'cal -3; read' >/dev/null &
+        ;;
+    2)
+        nohup "${TERMINAL}" -e "${EDITOR}" "$0" >/dev/null &
+        ;;
+esac
+
+icon=""
+val="$(date '+%a %b %d %H:%M %Y')"
+
+printf "%s %s\n" "${icon}" "${val}"
diff --git a/scripts/disk.sh b/scripts/disk.sh
new file mode 100755 (executable)
index 0000000..20745ad
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+location=${1:-/}
+
+[[ -d ${location} ]] || exit
+
+case ${BLOCK_BUTTON} in
+    1)
+        notify-send "Disk space" "$(df -h --output=target,used,size)"
+        ;;
+    2)
+        nohup "${TERMINAL}" -e "${EDITOR}" "$0" >/dev/null &
+        ;;
+esac
+
+case ${location} in
+    "/home"* )
+        icon=""
+        ;;
+    "/mnt"* )
+        icon=""
+        ;;
+    *)
+        icon=""
+        ;;
+esac
+
+printf "%s %s\n" "${icon}" "$(df -h ${location} | awk ' /[0-9]/ {print $3 "/" $2}')"
+
diff --git a/scripts/i3b-formatter.sh b/scripts/i3b-formatter.sh
new file mode 100755 (executable)
index 0000000..bf2300f
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+panel_backgroud=$(xrdb -query | grep '*.panel_background' | awk '{print $NF}')
+focused_background=$(xrdb -query | grep '*.ws_focused' | awk '{print $NF}')
+text=$(xrdb -query | grep '*.text_color' | awk '{print $NF}')
+
+i=0
+while IFS= read -r input; do
+    if (( $i == 0 )); then
+        value="${input}"
+    fi
+    if (( $i == 1 )); then
+        foreground="${input}"
+    fi
+    if (( $i == 2 )); then
+        background="${input}"
+    fi
+
+    i=$(( $i + 1 ))
+done
+
+while getopts "sr" opt; do
+    case ${opt} in
+        s)
+            separator="yes"
+            ;;
+        r)
+            reversed="yes"
+            ;;
+        \?)
+            echo "Invalid option"
+            exit 1
+            ;;
+    esac
+done
+
+if [[ -z ${separator} ]]; then
+    if [[ -z ${reversed} ]]; then
+        foreground=${foreground:-${text}}
+        background=${background:-${panel_backgroud}}
+    else
+        foreground=${foreground:-${text}}
+        background=${background:-${focused_background}}
+    fi
+else
+    if [[ -z ${reversed} ]]; then
+        foreground=${foreground:-${focused_background}}
+        background=${background:-${panel_backgroud}}
+    else
+        foreground=${foreground:-${panel_backgroud}}
+        background=${background:-${focused_background}}
+    fi
+fi
+
+echo "${value}"
+echo ""
+echo "${foreground}"
+echo "${background}"
+
index a08a5618f38fff2e3ed6a87d5563ecb237f0bb99..495150564e9135d53b77a898f78470106f2c7708 100755 (executable)
@@ -1,18 +1,33 @@
 #!/bin/bash
 
 #Pass the password to the block instance
-if [[ -n $BLOCK_INSTANCE ]]; then
+[[ -n $BLOCK_INSTANCE ]] && \
     password=("-h" "${BLOCK_INSTANCE}@localhost")
-fi
 
 filter() {
     tr '\n' ' ' | grep -Po '.*(?= \[playing\])|paused' | tr -d '\n'
 }
 
+icon=""
+
 case $BLOCK_BUTTON in
-    1) mpc $password status | filter && $TERMINAL -e ncmpcpp & disown ;; # right click pause/unpause
-    3) mpc $password toggle | filter ;; # right click, pause/unpause
-    4) mpc $password prev   | filter ;; # scroll up, previous
-    5) mpc $password next   | filter ;; # scroll down, next
-    *) mpc $password status | filter ;;
+    1)
+        out=$(mpc $password status | filter)
+        [[ -n ${out} ]] && nohup $TERMINAL -e ncmpcpp >/dev/null &
+        ;; # left click run ncmpcpp
+    3)
+        out=$(mpc $password toggle | filter)
+        ;; # right click, pause/unpause
+    4)
+        out=$(mpc $password prev | filter)
+        ;; # scroll up, previous
+    5)
+        out=$(mpc $password next | filter)
+        ;; # scroll down, next
+    *)
+        out=$(mpc $password status | filter)
+        ;;
 esac
+
+[[ -n ${out} ]] && \
+    printf "%s %s\n" "${icon}" "${out}"
index 231e54185dbd59426c997555dc7146d18ec9f0bb..053b768f3fef7c9e0e7dcdd54eda1cbf2f07daf1 100755 (executable)
@@ -20,5 +20,6 @@ case $1 in
 esac
 
 ipaddr=$(ip addr show enp3s0 | awk '/inet/ { print $2 ; exit }' | sed 's/\/.*//g')
-#echo $ipaddr
-printf '<span foreground="#66ff33">%s</span>' "${icon} ${ipaddr}"
+
+echo "${icon} ${ipaddr}"
+echo "#66ff33"
diff --git a/scripts/key-map.sh b/scripts/key-map.sh
deleted file mode 100755 (executable)
index 391ac29..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-setxkbmap -layout us,ru -option grp:ctrls_toggle
index 6fefaed4a7868f42bfd69d8d0ead9d063d7c3480..0c8aba338384c1cf0d05dd1c86c7bb5521b2db02 100755 (executable)
@@ -1,4 +1,15 @@
  #!/bin/bash
 
-xkb-switch
-xkb-switch -W
+i3bkeymapfile="${HOME}/.cache/i3b_pid_keymap"
+icon=""
+i3bpid="$(cat ${i3bkeymapfile})"
+i3bpidcur="$(pidof i3blocks)"
+
+if [[ ${i3bpid} == ${i3bpidcur} ]]; then
+    xkb-switch -n
+else
+    echo "${i3bpidcur}" > "${i3bkeymapfile}"
+fi
+
+out="$(xkb-switch)"
+printf "%s %s\n" "${icon}" "${out}"
index 50d4bc90083f784b99f764a1d8b203837542e241..40d9f443b015d062ecca247f97e61837a0f31b00 100755 (executable)
@@ -18,8 +18,18 @@ mem_info() {
     echo "${fmt_msg}"
 }
 
+export consumption_list="$(mem_info)"
+
 case $BLOCK_BUTTON in
-    1) notify-send "Top 10 memory consumption" "$(mem_info)" -t 30000;;
+    1)
+        notify-send "Top 10 memory consumption" "$(mem_info)" -t 30000
+        ;;
+    2)
+        nohup "${TERMINAL}" -e "${EDITOR}" "$0" >/dev/null &
+        ;;
 esac
 
-free -h | awk '/^Mem:/ {print $3 "/" $2}' | sed 's/i//g'
+icon=
+val=$(free -h | awk '/^Mem:/ {print $3 "/" $2}' | sed 's/i//g'i)
+
+echo "${icon} ${val}"
diff --git a/scripts/nettraf.sh b/scripts/nettraf.sh
new file mode 100755 (executable)
index 0000000..4d900ea
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+logfile="${HOME}/.cache/netlog"
+prevdata="$(cat ${logfile})"
+
+rxcur="$(($(cat /sys/class/net/*/statistics/rx_bytes | paste -sd '+')))"
+txcur="$(($(cat /sys/class/net/*/statistics/tx_bytes | paste -sd '+')))"
+rx="$(((rxcur-${prevdata%% *})/1024))"
+tx="$(((txcur-${prevdata##* })/1024))"
+
+echo "${rxcur} ${txcur}" > "${logfile}"
+
+printf "%sKiB%sKiB\n" "${rx}" "${tx}"
index 681ab82610b189416f58059808070af9cd387354..e646f157b9c9a19940caecd0f4c083c6f4f8603e 100755 (executable)
@@ -2,26 +2,35 @@
 
 sink=$( pactl list short sinks | sed -e 's,^\([0-9][0-9]*\)[^0-9].*,\1,' | tail -n 1 )
 
-case $BLOCK_BUTTON in
-     2) pactl set-sink-mute $sink toggle ;;
-     4) pactl set-sink-volume $sink +5% ;;
-     5) pactl set-sink-volume $sink -5% ;;
+case ${BLOCK_BUTTON} in
+    2)
+        nohup "${TERMINAL}" -e "${EDITOR}" "$0" >/dev/null &
+        ;;
+    3)
+        pactl set-sink-mute $sink toggle
+        ;;
+    4)
+        pactl set-sink-volume $sink +5%
+        ;;
+    5)
+        pactl set-sink-volume $sink -5%
+        ;;
 esac
 
 muted=$( awk '/muted/ {print $2}' <(pacmd list-sinks | grep '^[[:space:]]muted:' | head -n $(( $sink + 1 )) | tail -n 1 ) )
 
 if [ "$muted" = "yes" ]; then
-  icon="🔇"
-  printf "%s\\n" "$icon"
+  icon=""
+  printf "%s\n" "$icon"
 else
   vol=$( pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $sink + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' )
   if [ "$vol" -gt 60 ]; then
-    icon="🔊"
+    icon=""
   elif [[ "$vol" -le 60 && "$vol" -gt 30 ]]; then
-    icon="🔉"
+    icon=""
   else
-    icon="🔈"
+    icon=""
   fi
 
-  printf "%s %s%%\\n" "$icon" "$vol"
+  printf "%s %s%%\n" "$icon" "$vol"
 fi
index 2e20fa1163e69da21656d8a977852751f112d6fd..db7560cd960b1ff327686b117f6d93e8e9c19ee1 100644 (file)
@@ -27,3 +27,5 @@ complete -cf sudo
 complete -cf man
 
 export EDITOR=vim
+
+. /usr/share/bash-completion/bash_completion
diff --git a/shell/init_scripts/kube.mrc b/shell/init_scripts/kube.mrc
new file mode 100644 (file)
index 0000000..9244b9d
--- /dev/null
@@ -0,0 +1,6 @@
+#    __         __
+#   / /____  __/ /_  ___
+#  / //_/ / / / __ \/ _ \
+# / ,< / /_/ / /_/ /  __/
+#/_/|_|\__,_/_.___/\___/
+source <(kubectl completion bash)
diff --git a/shell/init_scripts/vault.mrc b/shell/init_scripts/vault.mrc
new file mode 100644 (file)
index 0000000..a796b04
--- /dev/null
@@ -0,0 +1,3 @@
+export PATH="/opt/vault:${PATH}"
+
+complete -C /opt/vault/vault vault