dots

git clone git://mattcarlson.org/repos/dots.git
Log | Files | Refs

commit fa3fec81dcad4e816f21c64721e49095531e9ef9
parent 2b4eebca3243e20d9bb86ca38a0a839038f29c0f
Author: Matthew Carlson <matt@mcarlson.xyz>
Date:   Mon, 16 Aug 2021 20:52:16 -0400

scripting; wpgtk keywords changed

Diffstat:
M.config/sh/aliasrc | 2+-
A.config/wpg/keywords.conf | 2++
M.config/wpg/wpg.conf | 3---
M.config/x/xprofile | 1+
M.config/x/xresources | 2+-
M.local/bin/bar/bat.sh | 2+-
M.local/bin/bar/cpu.sh | 10++++++----
M.local/bin/bar/light.sh | 2+-
M.local/bin/bar/mail.sh | 1+
M.local/bin/bar/monitor.sh | 2+-
M.local/bin/bar/music.sh | 3++-
M.local/bin/bar/net.sh | 230++++++++++++++++++++++++++++---------------------------------------------------
M.local/bin/bar/vol.sh | 1+
A.local/bin/menu.sh | 20++++++++++++++++++++
A.local/bin/pass.sh | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
M.local/share/gnupg/gpg-agent.conf | 2+-
16 files changed, 182 insertions(+), 164 deletions(-)

diff --git a/.config/sh/aliasrc b/.config/sh/aliasrc @@ -69,7 +69,7 @@ alias \ alias dots='/usr/bin/git --git-dir=${HOME}/.dots/ --work-tree=${HOME}' # sync mail on mail exit when entered thru cmd line -alias ${MAIL_CLIENT}='${MAIL_CLIENT} && { mail.sh -g & }' +alias ${MAIL_CLIENT}='${MAIL_CLIENT}; mail.sh -g &' # youtube alias \ diff --git a/.config/wpg/keywords.conf b/.config/wpg/keywords.conf @@ -0,0 +1,2 @@ +[default] +active = {color2} diff --git a/.config/wpg/wpg.conf b/.config/wpg/wpg.conf @@ -11,6 +11,3 @@ alpha = 100 smart_sort = true auto_adjust = false reload = true - -[keywords] -active = {color2} diff --git a/.config/x/xprofile b/.config/x/xprofile @@ -8,4 +8,5 @@ feh --no-fehbg --bg-scale "${XDG_DATA_HOME:-${HOME}/.local/share/}/wp" "${BAR}" & xcompmgr & mpd & +unclutter & xset r rate 250 50 diff --git a/.config/x/xresources b/.config/x/xresources @@ -70,7 +70,7 @@ herbe.font_color : col7 herbe.font_pattern : monospace:size=16 herbe.line_spacing : 5 herbe.padding : 5 -herbe.width : 285 +herbe.width : 297 herbe.border_size : 3 herbe.pos_x : 15 herbe.pos_y : 44 diff --git a/.local/bin/bar/bat.sh b/.local/bin/bar/bat.sh @@ -38,7 +38,7 @@ bar() { main() { # no bat and return - [ -d "${BAT}" ] || return + [ -d "${BAT}" ] || return 1 # uevent holds battery variables [ -f "${BAT}/uevent" ] && . "${BAT}/uevent" 2>/dev/null diff --git a/.local/bin/bar/cpu.sh b/.local/bin/bar/cpu.sh @@ -27,12 +27,12 @@ calculate_temp() { calculate_usage() { # perform math on cpu numbers from /proc/stat to get usage printf '%s\n' "$({ cat /proc/stat; sleep "${DELAY}"; cat /proc/stat; } | - awk '/^cpu / {usr=$2-usr; sys=$4-sys; idle=$5-idle; iow=$6-iow} - END {total=usr+sys+idle+iow; printf "%.0f\n", (total-idle)*100/total}')" > "${USAGE}" + awk '/^cpu / { usr=$2-usr; sys=$4-sys; idle=$5-idle; iow=$6-iow } + END { total=usr+sys+idle+iow; printf "%.0f\n", (total-idle)*100/total }')" > "${USAGE}" } # top ten intensive processes -get_procs() { ps -Ao comm,pcpu --sort=-pcpu | head -n 11 | tail -n -10 | sed 's/$/%/' ; } +get_procs() { ps -eo comm,%cpu | sort -k 2 -n -r | head | tail | sed 's/$/%/' ; } get_usage() { [ -f "${USAGE}" ] && usage=$(cat "${USAGE}") ; } @@ -60,7 +60,9 @@ main() { [ ${#} -eq 0 ] && bar # bar usage - case ${BLOCK_BUTTON} in esac + case ${BLOCK_BUTTON} in + 1) env HERBE_ID=/1 herbe "$(get_procs)" ;; + esac } main "${@}" diff --git a/.local/bin/bar/light.sh b/.local/bin/bar/light.sh @@ -53,7 +53,7 @@ bar() { main() { # run only if backlight found - [ -d "${LIGHT}" ] || return + [ -d "${LIGHT}" ] || return 1 # called from bar [ ${#} -eq 0 ] && bar diff --git a/.local/bin/bar/mail.sh b/.local/bin/bar/mail.sh @@ -54,6 +54,7 @@ main() { g) get_mail ;; # open mail if o flag used o) open ;; + *) return ;; esac done } diff --git a/.local/bin/bar/monitor.sh b/.local/bin/bar/monitor.sh @@ -9,7 +9,7 @@ VCP_CODE=10 BRIGHTNESS="${XDG_CACHE_HOME:-${HOME}/.cache/}/bar/brightness" get_brightness() { - [ ! -f "${BRIGHTNESS}" ] && return + [ ! -f "${BRIGHTNESS}" ] && return 1 # brightness cache should contain only number ! brightness=$(grep '^[0-9][0-9]*$' "${BRIGHTNESS}") && return diff --git a/.local/bin/bar/music.sh b/.local/bin/bar/music.sh @@ -37,7 +37,8 @@ main() { while getopts 'o' opt; do case "${opt}" in # open music player if called with o flag - o) open ;; + o) open ;; + *) return ;; esac done } diff --git a/.local/bin/bar/net.sh b/.local/bin/bar/net.sh @@ -2,161 +2,91 @@ # # net -NEWLINE=' -' - -net_menu() { - main_menu() { - # get first 802.11 capable device from /sys/class/net - interface="$(for dev in /sys/class/net/*; do - [ -e "${dev}/wireless" ] && printf '%s\n' "${dev##*/}" - done | head -n 1)" - - # scan interface - iwctl station "${interface}" scan - - # get available networks and known networks - get_network_info "iwctl station ${interface} get-networks" 'iwctl known-networks list' - - # user can connect, disconnect, or forget network - # don't care bout access points or other stuff - show_menu 'Wifi Menu' 'Connect' 'Disconnect' 'Forget' - } - - connect() { - # user can choose network to connect to - network="$(show_menu 'Connect' "${available_network_names}")" - - # if network starts with '> ' it means user is already on that network - case "${network}" in '> '*) printf 'Already connected to this network\n' && return ;; esac - - # if network is known connect with no passphrase - if printf '%s\n' "${known_network_info}" | awk -F '|' '{print $1}' | grep -iq "\<${network}\>"; then - iwctl station "${interface}" connect "${network}" - return - fi - - # if network is wep, psk, or 8021x get passphrase - case "$(printf '%s\n' "${available_network_info}" | grep -i "\<${network}\>" | awk -F '|' '{print $2}')" in - 'wep'|'psk'|'8021x') get_passphrase ;; - # if open just connect without passphrase - 'open') iwctl station "${interface}" connect "${network}" ;; - esac +ERROR_ICON='' +ETH_ICON='' +WIFI_HIGH_ICON='' +WIFI_MED_ICON='' +WIFI_LOW_ICON='' +WIFI_NO_ICON='' + +get_interface() { + # get path to interface + interface="$(for dev in /sys/class/net/*; do + case "${1}" in + # wifi will have a wireless/ dir + 'wifi') [ -d "${dev}/wireless/" ] && [ "$(cat "${dev}/carrier")" -eq 1 ] && printf '%s\n' "${dev}" ;; + 'eth') [ -d "${dev}/device/" ] && [ ! -d "${dev}/wireless/" ] && [ "$(cat "${dev}/carrier")" -eq 1 ] && printf '%s\n' "${dev}" ;; + esac + done | head -n 1)" + # isolate interface name + interface="${interface##*/}" +} + +get_wifi() { + get_interface 'wifi' + + # get ssid using iw + ssid="$(iw dev "${interface}" info | grep -i '\<ssid\>' | awk '{ print $2 }')" + + # no ssid means no wifi + [ -z "${ssid}" ] && return 1 + + # Get wifi strength + get_wifi_strength + + # one, two, or three bars depending on strength + case "${wifi_strength}" in + 3[0-9]|4[0-9]|50) WIFI_ICON="${WIFI_HIGH_ICON}" ;; + 5[1-9]|6[0-9]|7[0-9]) WIFI_ICON="${WIFI_MED_ICON}" ;; + 8[0-9]) WIFI_ICON="${WIFI_LOW_ICON}" ;; + 90) WIFI_ICON="${WIFI_NO_ICON}" ;; + esac + + wifi="${WIFI_ICON} ${ssid}" +} + +get_eth() { + get_interface 'eth' - # connect with passphrase - [ -n "${passphrase}" ] && iwctl --passphrase "${passphrase}" station "${interface}" connect "${network}" - } - - disconnect() { - connected_network="$(iwctl station "${interface}" show | grep -i '\<Connected network\>' | awk '{ $1=""; $2=""; sub(" ", " "); {$1=$1;print} }')" - if [ -n "${connected_network}" ]; then - answer="$(show_menu "Disconnect from ${connected_network}?" 'Yes' 'No')" - case "$(printf '%s\n' "${answer}" | tr '[:upper:]' '[:lower:]')" in - 'yes') iwctl station "${interface}" disconnect ;; - 'no') return ;; - esac - fi - } - - forget() { - # if there are known networks - if [ -n "${known_network_names}" ]; then - # get network - network="$(show_menu 'Forget' "${known_network_names}")" - - # get confirmation - answer="$(show_menu "Forget ${network}?" 'Yes' 'No')" - - # forget if answer is yes - [ "${answer}" = 'Yes' ] && iwctl known-networks "${network}" forget - fi - } - - # get network columns separately - get_network_column() { - types='open|wep|psk|8021x' - printf '%s\n' "${info}" | awk -v var="${1}" -F "\\${types}" '{ print $var }' | sed 's/^[ \t]*//;s/[ \t]*$//' - } - - get_network_info() { - if [ "${1}" = "iwctl station ${interface} get-networks" ]; then - info="$(eval "${1}" | grep '\s' | tail +3 | awk '{ $1 = $1 }; 1' | sed -e 's/\x1b\[[0-9;]*m//g')" - - available_network_names="$(get_network_column '1')" - available_network_types="$(printf '%s\n' "${info}" | awk '{ for (i=1;i<=NF;i++){ if ($i ~ /open|wep|psk|8021x/) { print $i } } }')" - available_network_strengths="$(get_network_column '2')" - - i=1 - available_network_info="$(printf '%s\n' "${available_network_names}" | ( while read -r name; do - type_field="$(printf '%s\n' "${available_network_types}" | sed -n ${i}p)" - strength_field="$(printf '%s\n' "${available_network_strengths}" | sed -n ${i}p)" - - if [ ${i} -eq 1 ]; then available_network_info="${name}|${type_field}|${strength_field}" - else available_network_info="${available_network_info}${NEWLINE}${name}|${type_field}|${strength_field}" - fi - - i=$((i+1)) - done - printf '%s\n' "${available_network_info}" ))" - fi - - if [ "${2}" = 'iwctl known-networks list' ]; then - info="$(eval "${2}" | grep '\s' | tail +3 | awk '{ $1 = $1 }; 1' | sed -e 's/\x1b\[[0-9;]*m//g')" - - known_network_names="$(get_network_column '1')" - known_network_types="$(printf '%s\n' "${info}" | awk '{ for (i=1;i<=NF;i++){ if ($i ~ /open|wep|psk|8021x/) { print $i } } }')" - known_network_dates="$(get_network_column '2')" - - i=1 - known_network_info="$(printf '%s\n' "${known_network_names}" | ( while read -r name; do - type_field="$(printf '%s\n' "${known_network_types}" | sed -n ${i}p)" - date_field="$(printf '%s\n' "${known_network_dates}" | sed -n ${i}p)" - - if [ ${i} -eq 1 ]; then known_network_info="${name}|${type_field}|${date_field}" - else known_network_info="${known_network_info}${NEWLINE}${name}|${type_field}|${date_field}" - fi - - i=$((i+1)) - done - printf '%s\n' "${known_network_info}" ))" - fi - } - - # hide input with dmenu -P flag - get_passphrase() { passphrase="$(dmenu -c -p 'Passphrase:' -P)" ; } - - show_menu() { - # first arg is prompt - prompt="${1}" - shift - - # remaining opts are options - options="$(for option in "${@}"; do - printf '%s\n' "${option}" - done)" - - # print using dmenu - answer="$(printf '%s\n' "${options}" | dmenu -c -l 10 -p "${prompt}")" - - # get user's answer - printf '%s\n' "${options}" | while read -r line; do - if [ "${line}" = "${answer}" ]; then - # if answer is a function run it else just print it - cmd="$(printf '%s\n' "${answer}" | tr '[:upper:]' '[:lower:]')" - if command -v "${cmd}" >/dev/null 2>&1 && [ "${cmd}" != 'yes' ]; then "${cmd}" - else printf '%s\n' "${answer}" - fi - break - fi - done - } - - main_menu + # eth unplugged or not working + [ -z "${interface}" ] && unset ETH_ICON + + eth="${ETH_ICON}" +} + +# measured in |dBm| +get_wifi_strength() { [ -e '/proc/net/wireless' ] && wifi_strength=$(grep -i "\<${interface}\>" '/proc/net/wireless' | awk '{ print $4 }' | sed 's/[^0-9]*//g') ; } + +bar() { + get_wifi + + get_eth + + # no wifi or eth and print error + [ -z "${wifi}" ] && [ -z "${eth}" ] && printf '%s\n' "${ERROR_ICON}" && return 1 + + # space needed between wifi and eth if eth is available + if [ -z "${eth}" ]; then printf '%s\n' "${wifi}${eth}" + else printf '%s\n' "${wifi} ${eth}" + fi } +open() { iwd-dmenu ; } main() { - net_menu + # called from bar + [ ${#} -eq 0 ] && bar + + # bar usage + case ${BLOCK_BUTTON} in 1) open ;; esac + + while getopts 'o' opt; do + case "${opt}" in + # open if o flag used + o) open ;; + *) return ;; + esac + done } main "${@}" diff --git a/.local/bin/bar/vol.sh b/.local/bin/bar/vol.sh @@ -67,6 +67,7 @@ main() { case "${opt}" in # toggle if t flag used t) toggle && return ;; + *) return ;; esac done diff --git a/.local/bin/menu.sh b/.local/bin/menu.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# +# menu + +main() { + xmenu << EOF | sh & +Applications + IMG:./icons/web.png Web Browser ${BROWSER} + IMG:./icons/gimp.png Image editor gimp + +Terminal (xterm) xterm +Terminal (urxvt) urxvt +Terminal (st) st + +Shutdown poweroff +Reboot reboot +EOF +} + +main "${@}" diff --git a/.local/bin/pass.sh b/.local/bin/pass.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# +# pass + +CREDENTIALS_DIR="${XDG_DATA_HOME:-${HOME}/.local/share/}/pass" +NEWLINE=' +' + +get_credential() { + credential="$(printf '%s\n' "${credentials}" | grep "\<${1}\>" | awk -F ':' '{ print $2 }')" + credential="${credential%\'}" + credential="${credential#\'}" +} + +main() { + i=0 + for site in "${CREDENTIALS_DIR}"/*.gpg; do + site="${site%.*}" + if [ ${i} -eq 0 ]; then sites="${sites}${site##*/}" + else sites="${sites}${NEWLINE}${site##*/}" + fi + i=$((i+1)) + done + + site="$(printf '%s\n' "${sites}" | dmenu -c -l 10)" + + credentials="$(gpg -dq "${CREDENTIALS_DIR}"/"${site}".gpg)" + + credential_types="$(printf '%s\n' "${credentials}" | awk -F ':' '{ print $1 }')" + + squestions="$(printf '%s\n' "${credential_types}" | grep -c 'squestion*')" + + credential_options="$(printf '%s\n' "${credential_types}" | ( while read -r type; do + case "${type}" in + 'uname') printf 'Username\n' ;; + 'pw') printf 'Password\n' ;; + 'email') printf 'Email\n' ;; + 'squestion'*) i=1 + while [ ${i} -le ${squestions} ]; do + printf '%s\n' "Security Question ${i}" + i=$((i+1)) + done + break + ;; + esac + done + printf '%s\n' "${credential_options}" ))" + + credential_option="$(printf '%s\n' "${credential_options}" | dmenu -c -l 10 -p 'Credentials')" + + if printf '%s\n' "${credential_option}" | grep -q '\<[0-9]\>'; then num="$(printf '%s\n' "${credential_option}" | awk '{ print $3 }')" ; fi + + case "${credential_option}" in + 'Username') get_credential 'uname' ;; + 'Password') get_credential 'pw' ;; + 'Email') get_credential 'email' ;; + "Security Question ${num}") get_credential "sanswer${num}" ;; + esac + + if printf '%s\n' "${credential}" | xclip -selection clipboard; then { herbe "${credential_option} for "${site}" copied to clipboard" & } ; fi +} + +main "${@}" diff --git a/.local/share/gnupg/gpg-agent.conf b/.local/share/gnupg/gpg-agent.conf @@ -3,4 +3,4 @@ default-cache-ttl 31557600 max-cache-ttl 31557600 # custom pinentry program -pinentry-program /home/mc/.local/bin/pin.sh +pinentry-program /home/mc/.local/bin/pin.sh