From: Dmitry Fedotov Date: Wed, 8 Jul 2020 12:17:15 +0000 (+0300) Subject: i3blocks scripts total rework. Add shell init scripts for vault and kubectl. X-Git-Url: https://www.git.dmfe.net/?a=commitdiff_plain;h=4655f588f8cf77de995b60d825235c2083330a55;p=dotfiles i3blocks scripts total rework. Add shell init scripts for vault and kubectl. --- diff --git a/scripts/cpu-temp.sh b/scripts/cpu-temp.sh index 4ffbcd9..02225b6 100755 --- a/scripts/cpu-temp.sh +++ b/scripts/cpu-temp.sh @@ -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 index 0000000..d93546f --- /dev/null +++ b/scripts/cpu-util.sh @@ -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 index 0000000..7303dd4 --- /dev/null +++ b/scripts/date-time.sh @@ -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 index 0000000..20745ad --- /dev/null +++ b/scripts/disk.sh @@ -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 index 0000000..bf2300f --- /dev/null +++ b/scripts/i3b-formatter.sh @@ -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}" + diff --git a/scripts/i3mpd.sh b/scripts/i3mpd.sh index a08a561..4951505 100755 --- a/scripts/i3mpd.sh +++ b/scripts/i3mpd.sh @@ -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}" diff --git a/scripts/iface.sh b/scripts/iface.sh index 231e541..053b768 100755 --- a/scripts/iface.sh +++ b/scripts/iface.sh @@ -20,5 +20,6 @@ case $1 in esac ipaddr=$(ip addr show enp3s0 | awk '/inet/ { print $2 ; exit }' | sed 's/\/.*//g') -#echo $ipaddr -printf '%s' "${icon} ${ipaddr}" + +echo "${icon} ${ipaddr}" +echo "#66ff33" diff --git a/scripts/key-map.sh b/scripts/key-map.sh deleted file mode 100755 index 391ac29..0000000 --- a/scripts/key-map.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -setxkbmap -layout us,ru -option grp:ctrls_toggle diff --git a/scripts/keymap-switch.sh b/scripts/keymap-switch.sh index 6fefaed..0c8aba3 100755 --- a/scripts/keymap-switch.sh +++ b/scripts/keymap-switch.sh @@ -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}" diff --git a/scripts/mem.sh b/scripts/mem.sh index 50d4bc9..40d9f44 100755 --- a/scripts/mem.sh +++ b/scripts/mem.sh @@ -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 index 0000000..4d900ea --- /dev/null +++ b/scripts/nettraf.sh @@ -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}" diff --git a/scripts/volume.sh b/scripts/volume.sh index 681ab82..e646f15 100755 --- a/scripts/volume.sh +++ b/scripts/volume.sh @@ -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 diff --git a/shell/init_scripts/bashrc.mrc b/shell/init_scripts/bashrc.mrc index 2e20fa1..db7560c 100644 --- a/shell/init_scripts/bashrc.mrc +++ b/shell/init_scripts/bashrc.mrc @@ -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 index 0000000..9244b9d --- /dev/null +++ b/shell/init_scripts/kube.mrc @@ -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 index 0000000..a796b04 --- /dev/null +++ b/shell/init_scripts/vault.mrc @@ -0,0 +1,3 @@ +export PATH="/opt/vault:${PATH}" + +complete -C /opt/vault/vault vault