dots

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

commit 2b4eebca3243e20d9bb86ca38a0a839038f29c0f
parent 077ae01d3415326adb12953dd5c5abc8bff3f043
Author: Matthew Carlson <matt@mcarlson.xyz>
Date:   Wed, 11 Aug 2021 23:35:08 -0400

some scripting

Diffstat:
M.config/mksh/mkshrc | 4++--
M.config/sh/aliasrc | 5++++-
M.config/sh/functionrc | 2+-
M.config/sh/profile | 8++++----
M.config/sx/sxrc | 2+-
M.config/x/xprofile | 4++--
M.config/x/xresources | 4++--
A.local/bin/bar/bat.sh | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
M.local/bin/bar/cpu.sh | 10++++------
M.local/bin/bar/date.sh | 12+++++++++++-
A.local/bin/bar/light.sh | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A.local/bin/bar/mail.sh | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
M.local/bin/bar/monitor.sh | 14++++++++------
M.local/bin/bar/music.sh | 11+++++------
M.local/bin/bar/net.sh | 6+++---
M.local/bin/bar/time.sh | 12+++++++++++-
M.local/bin/bar/vol.sh | 37++++++++++++++++++++++++-------------
M.local/bin/lock.sh | 28++++++++++++++++------------
M.local/bin/open.sh | 134+++++++++++++++++++++++++++++++++++++++++--------------------------------------
M.local/bin/shot.sh | 30+++++++++++++++++-------------
M.local/bin/sys.sh | 12++++++++----
M.local/bin/wm.sh | 4+++-
M.local/bin/wp.sh | 10+++++-----
A.local/share/gnupg/gpg-agent.conf | 6++++++
24 files changed, 394 insertions(+), 149 deletions(-)

diff --git a/.config/mksh/mkshrc b/.config/mksh/mkshrc @@ -35,7 +35,7 @@ GPG_TTY="$(tty)" export GPG_TTY # aliasrc -[ -f "${XDG_CONFIG_HOME:-${HOME}/.config}/sh/aliasrc" ] && . "${XDG_CONFIG_HOME:-${HOME}/.config}/sh/aliasrc" +[ -f "${XDG_CONFIG_HOME:-${HOME}/.config/}/sh/aliasrc" ] && . "${XDG_CONFIG_HOME:-${HOME}/.config/}/sh/aliasrc" # functionrc -[ -f "${XDG_CONFIG_HOME:-${HOME}/.config}/sh/functionrc" ] && . "${XDG_CONFIG_HOME:-${HOME}/.config}/sh/functionrc" +[ -f "${XDG_CONFIG_HOME:-${HOME}/.config/}/sh/functionrc" ] && . "${XDG_CONFIG_HOME:-${HOME}/.config/}/sh/functionrc" diff --git a/.config/sh/aliasrc b/.config/sh/aliasrc @@ -24,7 +24,7 @@ if uname -s | grep -i 'linux' >/dev/null 2>&1; then echo='echo -en' \ egrep='egrep --color=auto' \ fgrep='fgrep --color=auto' \ - ft='grep -nwIR' \ + ft='grep -inwIR' \ grep='grep --color=auto' \ ls='ls -ahls --color=auto --group-directories-first' \ mv='mv -v' \ @@ -68,6 +68,9 @@ alias \ # dots 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 & }' + # youtube alias \ yt='youtube-dl -i -o "${DOWNLOADS_DIR}/%(uploader)s/%(title)s.%(ext)s" --add-metadata' \ diff --git a/.config/sh/functionrc b/.config/sh/functionrc @@ -2,7 +2,7 @@ # # functionrc -f() { fff "${@}" && cd "$(cat "${XDG_CACHE_HOME:-${HOME}/.cache}/fff/.fff_d")" || exit ; } +f() { fff "${@}" && cd "$(cat "${XDG_CACHE_HOME:-${HOME}/.cache/}/fff/.fff_d")" || exit ; } s() { du -a "${HOME}" | awk '{ $1="" } { gsub("^ ", "", $0); print "\"" $0 "\"" }' | fzf | sed -e 's/^.//' -e 's/.$//' | open.sh ; } rands() { </dev/urandom tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | head -c "${1}"; printf '\n' ; } rp() { for f in *; do mv "${f}" "$(printf '%s\n' "${f}" | sed "s/${1}/${2}/g")"; done ; } diff --git a/.config/sh/profile b/.config/sh/profile @@ -28,12 +28,12 @@ export XDG_CACHE_HOME="${HOME}/.cache/" export XDG_STATE_HOME="${HOME}/.local/state/" # xdg base directory support -export VIMINIT="source ${XDG_CONFIG_HOME:-${HOME}/.config}/vim/vimrc" -export GNUPGHOME="${XDG_DATA_HOME:-${HOME}/.local/share}/gnupg/" -export ENV="${XDG_CONFIG_HOME:-${HOME}/.config}/mksh/mkshrc" +export VIMINIT="source ${XDG_CONFIG_HOME:-${HOME}/.config/}/vim/vimrc" +export GNUPGHOME="${XDG_DATA_HOME:-${HOME}/.local/share/}/gnupg/" +export ENV="${XDG_CONFIG_HOME:-${HOME}/.config/}/mksh/mkshrc" export HISTFILE='' export XAUTHORITY="${XDG_RUNTIME_DIR}/xauth" -export YTFZF_CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}/ytfzf/" +export YTFZF_CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config/}/ytfzf/" export YTFZF_CONFIG_FILE="${YTFZF_CONFIG_DIR}/ytfzf.sh" export STARDICT_DATA_DIR="${XDG_DATA_HOME:-${HOME}/.local/share/}" diff --git a/.config/sx/sxrc b/.config/sx/sxrc @@ -2,6 +2,6 @@ # # sxrc -. "${XDG_CONFIG_HOME:-${HOME}/.config}/x/xprofile" +. "${XDG_CONFIG_HOME:-${HOME}/.config/}/x/xprofile" "${WM}" >/dev/null 2>&1 diff --git a/.config/x/xprofile b/.config/x/xprofile @@ -2,9 +2,9 @@ # # xprofile -xrdb "${XDG_CONFIG_HOME:-${HOME}/.config}/x/xresources" +xrdb "${XDG_CONFIG_HOME:-${HOME}/.config/}/x/xresources" lock.sh & -feh --no-fehbg --bg-scale "${XDG_DATA_HOME:-${HOME}/.local/share}/wp" +feh --no-fehbg --bg-scale "${XDG_DATA_HOME:-${HOME}/.local/share/}/wp" "${BAR}" & xcompmgr & mpd & diff --git a/.config/x/xresources b/.config/x/xresources @@ -70,10 +70,10 @@ herbe.font_color : col7 herbe.font_pattern : monospace:size=16 herbe.line_spacing : 5 herbe.padding : 5 -herbe.width : 350 +herbe.width : 285 herbe.border_size : 3 herbe.pos_x : 15 -herbe.pos_y : 42 +herbe.pos_y : 44 herbe.corner : 3 herbe.duration : 5 diff --git a/.local/bin/bar/bat.sh b/.local/bin/bar/bat.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# +# bat + +# just handle one battery +BAT='/sys/class/power_supply/BAT0/' +BAT_CHARGING_ICON='' +BAT_WARNING_ICON='' +BAT_EMPTY_ICON='' +BAT_QUARTER_ICON='' +BAT_HALF_ICON='' +BAT_THREE_QUARTERS_ICON='' +BAT_FULL_ICON='' + +get_energy_left() { + energy_left="$(printf '%.2f' "$(printf '%s\n' "scale=4; ${POWER_SUPPLY_ENERGY_FULL}/${POWER_SUPPLY_ENERGY_FULL_DESIGN} * 100" | bc)")" + env HERBE_ID=/0 herbe "Energy left: ${energy_left}%" +} + +bar() { + # prefix could be charging, warning, or both + PREFIX='' + + # if charging then append charging icon to prefix + [ "${POWER_SUPPLY_STATUS}" = 'Charging' ] && PREFIX="${PREFIX}${BAT_CHARGING_ICON} " + + # battery icon split into empty, quarter, half, three-quarters, and full + case ${POWER_SUPPLY_CAPACITY} in + 0) ICON="${BAT_EMPTY_ICON}" && PREFIX="${PREFIX}${BAT_WARNING_ICON} " ;; + [1-9]|1[0-9]|2[0-5]) ICON="${BAT_QUARTER_ICON}" && PREFIX="${PREFIX}${BAT_WARNING_ICON} " ;; + 2[6-9]|3[0-9]|4[0-9]|50) ICON="${BAT_HALF_ICON}" ;; + 5[1-9]|6[0-9]|7[0-5]) ICON="${BAT_THREE_QUARTERS_ICON}" ;; + 7[6-9]|8[0-9]|9[0-9]|100) ICON="${BAT_FULL_ICON}" ;; + esac + + printf '%s\n' "${PREFIX}${ICON} ${POWER_SUPPLY_CAPACITY}%" +} + +main() { + # no bat and return + [ -d "${BAT}" ] || return + + # uevent holds battery variables + [ -f "${BAT}/uevent" ] && . "${BAT}/uevent" 2>/dev/null + + # called from bar + [ ${#} -eq 0 ] && bar + + # bar usage + case ${BLOCK_BUTTON} in + 1) get_energy_left ;; + esac +} + +main "${@}" diff --git a/.local/bin/bar/cpu.sh b/.local/bin/bar/cpu.sh @@ -16,7 +16,7 @@ DELAY=3.15 TEMP="$(ls /sys/class/thermal/thermal_zone2*/temp)" # cache used b/c awk and delay is time expensive -USAGE="${XDG_CACHE_HOME:-${HOME}/.cache}/bar/usage" +USAGE="${XDG_CACHE_HOME:-${HOME}/.cache/}/bar/usage" calculate_temp() { [ -f "${TEMP}" ] && temp=$(cat "${TEMP}") @@ -36,7 +36,7 @@ get_procs() { ps -Ao comm,pcpu --sort=-pcpu | head -n 11 | tail -n -10 | sed 's/ get_usage() { [ -f "${USAGE}" ] && usage=$(cat "${USAGE}") ; } -show() { +bar() { # temp calculate_temp case ${temp} in @@ -57,12 +57,10 @@ show() { main() { # called from bar - [ ${#} -eq 0 ] && show + [ ${#} -eq 0 ] && bar # bar usage - case "${BLOCK_BUTTON}" in - *) ;; - esac + case ${BLOCK_BUTTON} in esac } main "${@}" diff --git a/.local/bin/bar/date.sh b/.local/bin/bar/date.sh @@ -4,4 +4,14 @@ ICON='' -printf '%s\n' "${ICON} $(date +%a,\ %Y-%m-%d)" +bar() { printf '%s\n' "${ICON} $(date +%Y-%m-%d)" ; } + +main() { + # called from bar + [ ${#} -eq 0 ] && bar + + # bar usage + case ${BLOCK_BUTTON} in 1) env HERBE_ID=/1 herbe "$(cal)" ;; esac +} + +main "${@}" diff --git a/.local/bin/bar/light.sh b/.local/bin/bar/light.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# +# light + +ICON='' +# intel_backlight for thinkpad at least +LIGHT='/sys/class/backlight/intel_backlight/' +# 852 on thinkpad not sure if universal +MAX_BRIGHTNESS="$([ -f "${LIGHT}/max_brightness" ] && cat "${LIGHT}/max_brightness")" + +get_brightness() { + # first get brightness as percentile of max brightness + brightness="$(cat "${LIGHT}/brightness")" + # then convert to percentage in terms of one hundred + brightness="$(printf '%s\n' "scale=10; (${brightness}/${MAX_BRIGHTNESS})*100" | bc)" + # dont care bout decimal + brightness="$(printf '%.0f\n' "${brightness}")" +} + +set_brightness() { + get_brightness + + if [ "${1}" = '+' ]; then + # convert brightness percentage to actual brightness units then add percentage in actual brightness units + if [ "${brightness}" -lt 100 ]; then brightness=$(printf '%s\n' "scale=10; ((${brightness}/100)*${MAX_BRIGHTNESS})+(${2}*(${MAX_BRIGHTNESS}/100))" | bc) + else return + fi + elif [ "${1}" = '-' ]; then + # same as above but substract + if [ "${brightness}" -gt 0 ]; then brightness=$(printf '%s\n' "scale=10; ((${brightness}/100)*${MAX_BRIGHTNESS})-(${2}*(${MAX_BRIGHTNESS}/100))" | bc) + else return + fi + fi + + # can the decimal + brightness="$(printf '%.0f\n' ${brightness})" + + # keep between 0 and max brightness + [ ${brightness} -lt 0 ] && brightness=0 + [ ${brightness} -gt ${MAX_BRIGHTNESS} ] && brightness=${MAX_BRIGHTNESS} + + # send brightness to file for future reading + printf '%s\n' ${brightness} > "${LIGHT}/brightness" + + env HERBE_ID=/0 herbe "Brightness: ${brightness}%" +} + +bar() { + get_brightness + + printf '%s\n' "${ICON} ${brightness}%" +} + +main() { + # run only if backlight found + [ -d "${LIGHT}" ] || return + + # called from bar + [ ${#} -eq 0 ] && bar + + # bar usage + case ${BLOCK_BUTTON} in + 4) set_brightness + 1 ;; + 5) set_brightness - 1 ;; + esac + + # adjust brightness based on args + # ${1} = +/- and ${2} = percentage + [ "${*}" ] && set_brightness "${1}" "${2}" +} + +main "${@}" diff --git a/.local/bin/bar/mail.sh b/.local/bin/bar/mail.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# +# mail + +ICON='' +GET_ICON='' +ISYNCRC="${XDG_CONFIG_HOME:-${HOME}/.config/}/isync/isyncrc" +# both personal and school mail +PERSONAL_MAIL_DIR="${MAIL_DIR}/matt/INBOX/new/" +SCHOOL_MAIL_DIR="${MAIL_DIR}/algomau/INBOX/new/" +TMP='/tmp/get-mail' + +# count mail files in dir +count_mail() { [ -e "${1}" ] && printf '%s\n' "${#}" || printf '%s\n' 0 ; } + +# use isync to get mail from server +get_mail() { + printf '%s\n' "${GET_ICON}" > "${TMP}" + mbsync -c "${ISYNCRC}" -aq + rm -f "${TMP}" +} + +open() { "${TERMINAL}" -c "${TERMINAL}" -e "${MAIL_CLIENT}" && { get_mail & } ; } + +bar() { + # count personal and school mail then sum together + personal_mail_count=$(count_mail "${PERSONAL_MAIL_DIR}"/*) + school_mail_count=$(count_mail "${SCHOOL_MAIL_DIR}"/*) + total_mail_count=$((personal_mail_count + school_mail_count)) + + # if getting mail show get icon + [ -f "${TMP}" ] && printf '%s\n' "${GET_ICON}" && return + + # if mail open show just mail icon + if ps -ef | grep -i "\<${MAIL_CLIENT}\>" | grep -iqv '\<grep\>'; then printf '%s\n' "${ICON}" + # otherwise print both icon and count + else printf '%s\n' "${ICON} ${total_mail_count}" + fi +} + +main() { + # called from bar + [ ${#} -eq 0 ] && bar + + # bar usage + case ${BLOCK_BUTTON} in + 1) open ;; + 2) get_mail ;; + esac + + while getopts 'go' opt; do + case "${opt}" in + # get mail if called with g flag + g) get_mail ;; + # open mail if o flag used + o) open ;; + esac + done +} + +main "${@}" diff --git a/.local/bin/bar/monitor.sh b/.local/bin/bar/monitor.sh @@ -6,7 +6,7 @@ ICON='' # brightness vcp code is 10 VCP_CODE=10 # cache used b/c ddcutil getvcp too expensive -BRIGHTNESS="${XDG_CACHE_HOME:-${HOME}/.cache}/bar/brightness" +BRIGHTNESS="${XDG_CACHE_HOME:-${HOME}/.cache/}/bar/brightness" get_brightness() { [ ! -f "${BRIGHTNESS}" ] && return @@ -32,26 +32,28 @@ set_brightness() { # set brightness using ddcutil doas ddcutil setvcp ${VCP_CODE} "${brightness}" >/dev/null 2>&1 + env HERBE_ID=/0 herbe "Brightness: ${brightness}%" & + # get actual brightness and send output to cache printf '%s\n' "$(doas ddcutil getvcp ${VCP_CODE} | awk '{ print $9 }' | tr -d '[:punct:]')" 2>/dev/null > "${BRIGHTNESS}" } -show() { +bar() { get_brightness printf '%s\n' "${ICON} ${brightness}%" } main() { # called from bar - [ ${#} -eq 0 ] && show + [ ${#} -eq 0 ] && bar - # bar options - case "${BLOCK_BUTTON}" in + # bar usage + case ${BLOCK_BUTTON} in 4) set_brightness + 25 ;; 5) set_brightness - 25 ;; esac - # set monitor brightness based on args + # modify monitor brightness based on args # ${1} = +/- and ${2} = percentage [ "${*}" ] && set_brightness "${1}" "${2}" } diff --git a/.local/bin/bar/music.sh b/.local/bin/bar/music.sh @@ -8,7 +8,7 @@ PAUSED_ICON='' open() { "${TERMINAL}" -c "${MUSIC_PLAYER}" -e "${MUSIC_PLAYER}" ; } -show() { +bar() { # get current song name song="$(mpc -f %title% | head -n 1)" # get state of song @@ -24,10 +24,10 @@ show() { main() { # called from bar - [ ${#} -eq 0 ] && show + [ ${#} -eq 0 ] && bar - # bar options - case "${BLOCK_BUTTON}" in + # bar usage + case ${BLOCK_BUTTON} in 1) open ;; 2) mpc -q toggle ;; 4) mpc -q prev ;; @@ -37,8 +37,7 @@ main() { while getopts 'o' opt; do case "${opt}" in # open music player if called with o flag - o) open ;; - *) return ;; + o) open ;; esac done } diff --git a/.local/bin/bar/net.sh b/.local/bin/bar/net.sh @@ -31,13 +31,13 @@ net_menu() { 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 -q "\<${network}\>"; then + 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 "\<${network}\>" | awk -F '|' '{print $2}')" in + 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}" ;; @@ -48,7 +48,7 @@ net_menu() { } disconnect() { - connected_network="$(iwctl station "${interface}" show | grep '\<Connected network\>' | awk '{ $1=""; $2=""; sub(" ", " "); {$1=$1;print} }')" + 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 diff --git a/.local/bin/bar/time.sh b/.local/bin/bar/time.sh @@ -4,4 +4,14 @@ ICON='' -printf '%s\n' "${ICON} $(date +%I:%M\ %p)" +bar() { printf '%s\n' "${ICON} $(date +%I:%M\ %p)" ; } + +main() { + # called from bar + [ ${#} -eq 0 ] && bar + + # bar usage + case ${BLOCK_BUTTON} in esac +} + +main "${@}" diff --git a/.local/bin/bar/vol.sh b/.local/bin/bar/vol.sh @@ -10,8 +10,8 @@ VOLUME_MUTED_ICON='' get_scontrol() { # Prefer Master but use PCM if not available - if amixer scontrols | grep -q 'Master'; then scontrol='Master' - elif amixer scontrols | grep -q 'PCM'; then scontrol='PCM' + if amixer scontrols | grep -iq 'Master'; then scontrol='Master' + elif amixer scontrols | grep -iq 'PCM'; then scontrol='PCM' fi } @@ -23,25 +23,29 @@ toggle() { } # set volume linearly -set_vol() { amixer set "${scontrol}" "${2}"%"${1}" -M ; } +set_vol() { + amixer set "${scontrol}" "${2}"%"${1}" -M + vol=$(get_vol) + env HERBE_ID=/0 herbe "Volume: ${vol}%" & +} -show() { +bar() { vol=$(get_vol) # check if muted if [ "${scontrol}" = 'Master' ] || [ "${scontrol}" = 'PCM' ]; then - if amixer get "${scontrol}" | sed 5q | grep -q '\[off\]' || \ - amixer get 'IEC958,5' | sed 4q | grep -q '\[off\]'; then + if amixer get "${scontrol}" | sed 5q | grep -iq '\[off\]' || \ + amixer get 'IEC958,5' | sed 4q | grep -iq '\[off\]'; then printf '%s\n' "${VOLUME_MUTED_ICON} ${vol}%" && return fi fi # volume 0 is off, 1-33 is low, 34-66 is med, 67-100 is high case ${vol} in - 100|9[0-9]|8[0-9]|7[0-9]|6[7-9]) printf '%s\n' "${VOLUME_HIGH_ICON} ${vol}%" ;; - 6[0-6]|5[0-9]|4[0-9]|3[4-9]) printf '%s\n' "${VOLUME_MID_ICON} ${vol}%" ;; - 3[0-3]|2[0-9]|1[0-9]|[1-9]) printf '%s\n' "${VOLUME_LOW_ICON} ${vol}%" ;; 0) printf '%s\n' "${VOLUME_OFF_ICON} ${vol}%" ;; + [1-9]|1[0-9]|2[0-9]|3[0-3]) printf '%s\n' "${VOLUME_LOW_ICON} ${vol}%" ;; + 3[4-9]|4[0-9]|5[0-9]|6[0-6]) printf '%s\n' "${VOLUME_MID_ICON} ${vol}%" ;; + 6[7-9]|7[0-9]|8[0-9]|9[0-9]|100) printf '%s\n' "${VOLUME_HIGH_ICON} ${vol}%" ;; esac } @@ -49,17 +53,24 @@ main() { get_scontrol # called from bar - [ ${#} -eq 0 ] && show + [ ${#} -eq 0 ] && bar - # bar options - case "${BLOCK_BUTTON}" in + # bar usage + case ${BLOCK_BUTTON} in 1) "${TERMINAL}" -c 'alsamixer' -e 'alsamixer' ;; 2) toggle ;; 4) set_vol + 1 ;; 5) set_vol - 1 ;; esac - # adjust volume based on args + while getopts 't' opt; do + case "${opt}" in + # toggle if t flag used + t) toggle && return ;; + esac + done + + # set volume based on args # ${1} = +/- and ${2} = percentage [ "${*}" ] && set_vol "${1}" "${2}" } diff --git a/.local/bin/lock.sh b/.local/bin/lock.sh @@ -4,23 +4,27 @@ SOCKETS_DIR="/tmp/mpv-sockets/" -mpc pause >/dev/null 2>&1; +main() { + mpc pause >/dev/null 2>&1; -for socket in "${SOCKETS_DIR}"/*; do - [ -e "${socket}" ] || break - printf 'set pause yes' | socat - "${socket}"; -done + for socket in "${SOCKETS_DIR}"/*; do + [ -e "${socket}" ] || break + printf 'set pause yes\n' | socat - "${socket}"; + done -bpid=$(ps -ef | grep "\<${BROWSER}\>" | grep -v '\<grep\>' | awk '{ printf "%s ", $2 }') + bpid=$(ps -ef | grep -i "\<${BROWSER}\>" | grep -iv '\<grep\>' | awk '{ printf "%s ", $2 }') -[ -n "${bpid}" ] && kill -STOP ${bpid} + [ -n "${bpid}" ] && kill -STOP ${bpid} -"${LOCKER}" + "${LOCKER}" -temp="$(mktemp)" + temp="$(mktemp)" -jobs -p > "${temp}" + jobs -p > "${temp}" -wait < "${temp}" + wait < "${temp}" -kill -CONT ${bpid} + kill -CONT ${bpid} +} + +main "${@}" diff --git a/.local/bin/open.sh b/.local/bin/open.sh @@ -2,75 +2,79 @@ # # open -if [ ${#} -eq 0 ]; then opt="$(tee -i)" -else opt="${*}" -fi +main() { + if [ ${#} -eq 0 ]; then opt="$(tee -i)" + else opt="${*}" + fi -case "${opt}" in - # audio - *.flac \ - | *.m4a \ - | *.mp3 \ - | *.ogg \ - | *.opus \ - | *.wav) - "${MEDIA_PLAYER}" --no-video "${opt}" - ;; + case "${opt}" in + # audio + *.flac \ + | *.m4a \ + | *.mp3 \ + | *.ogg \ + | *.opus \ + | *.wav) + "${MEDIA_PLAYER}" --no-video "${opt}" + ;; - # document - *.djvu \ - | *.epub \ - | *.pdf) - "${READER}" "${opt}" - ;; + # document + *.djvu \ + | *.epub \ + | *.pdf) + "${READER}" "${opt}" + ;; - # gif - *.gif) - "${MEDIA_PLAYER}" --loop "${opt}" - ;; + # gif + *.gif) + "${MEDIA_PLAYER}" --loop "${opt}" + ;; - # image - *.bmp \ - | *.dib \ - | *.ff \ - | *.ico \ - | *.iff \ - | *.jfi \ - | *.jfif \ - | *.jif \ - | *.jpe \ - | *.jpeg \ - | *.jpg \ - | *.lbm \ - | *.png \ - | *.pnm \ - | *.tga \ - | *.tif \ - | *.tiff \ - | *.webp \ - | *.xpm) - "${IMG_VIEWER}" "${opt}" - ;; + # image + *.bmp \ + | *.dib \ + | *.ff \ + | *.ico \ + | *.iff \ + | *.jfi \ + | *.jfif \ + | *.jif \ + | *.jpe \ + | *.jpeg \ + | *.jpg \ + | *.lbm \ + | *.png \ + | *.pnm \ + | *.tga \ + | *.tif \ + | *.tiff \ + | *.webp \ + | *.xpm) + "${IMG_VIEWER}" "${opt}" + ;; - # video - *.avi \ - | *.mkv \ - | *.mp4 \ - | *.webm) - "${MEDIA_PLAYER}" "${opt}" - ;; + # video + *.avi \ + | *.mkv \ + | *.mp4 \ + | *.webm) + "${MEDIA_PLAYER}" "${opt}" + ;; - # web/vector - *.htm \ - | *.html \ - | *.php \ - | *.svg \ - | *.xhtml) - "${BROWSER}" "${opt}" - ;; + # web/vector + *.htm \ + | *.html \ + | *.php \ + | *.svg \ + | *.xhtml) + "${BROWSER}" "${opt}" + ;; - # everything else - *) - exec "${EDITOR:-vi}" "${opt}" </dev/tty - ;; -esac + # everything else + *) + exec "${EDITOR:-vi}" "${opt}" </dev/tty + ;; + esac +} + +main "${@}" diff --git a/.local/bin/shot.sh b/.local/bin/shot.sh @@ -2,22 +2,26 @@ # # shot -COLORS="${XDG_CACHE_HOME:-${HOME}/.cache}/wal/colors.sh" +COLORS="${XDG_CACHE_HOME:-${HOME}/.cache/}/wal/colors.sh" -[ -f "${COLORS}" ] && . "${COLORS}" +main() { + [ -f "${COLORS}" ] && . "${COLORS}" -hex="$(printf '%s' "${color4}" | tr '[:lower:]' '[:upper:]' | tr -d '[:punct:]')" + hex="$(printf '%s' "${color4}" | tr '[:lower:]' '[:upper:]' | tr -d '[:punct:]')" -a=$(printf '%s' "${hex}" | cut -c 1-2) -b=$(printf '%s' "${hex}" | cut -c 3-4) -c=$(printf '%s' "${hex}" | cut -c 5-6) + a=$(printf '%s' "${hex}" | cut -c 1-2) + b=$(printf '%s' "${hex}" | cut -c 3-4) + c=$(printf '%s' "${hex}" | cut -c 5-6) -r=$(printf '%s\n' "ibase=16; ${a}" | bc) -g=$(printf '%s\n' "ibase=16; ${b}" | bc) -b=$(printf '%s\n' "ibase=16; ${c}" | bc) + r=$(printf '%s\n' "ibase=16; ${a}" | bc) + g=$(printf '%s\n' "ibase=16; ${b}" | bc) + b=$(printf '%s\n' "ibase=16; ${c}" | bc) -rf=$(printf '%s\n' "scale=10; ${r}/255" | bc) -gf=$(printf '%s\n' "scale=10; ${g}/255" | bc) -bf=$(printf '%s\n' "scale=10; ${b}/255" | bc) + rf=$(printf '%s\n' "scale=10; ${r}/255" | bc) + gf=$(printf '%s\n' "scale=10; ${g}/255" | bc) + bf=$(printf '%s\n' "scale=10; ${b}/255" | bc) -scrot -a "$(slop -b 3 -c "${rf}","${gf}","${bf}",1.0 -f '%x,%y,%w,%h')" -q 100 -z -C 'screenshot' "${HOME}/pix/captures/%m-%d-%Y-%I-%M-%S.png" + scrot -a "$(slop -b 3 -c "${rf}","${gf}","${bf}",1.0 -f '%x,%y,%w,%h')" -q 100 -z -C 'screenshot' "${HOME}/pix/captures/%m-%d-%Y-%I-%M-%S.png" +} + +main "${@}" diff --git a/.local/bin/sys.sh b/.local/bin/sys.sh @@ -8,10 +8,14 @@ CMDS="\  Restart doas shutdown -r now " -lines=$(printf '%s' "${CMDS}" | grep -c '^') +main() { + lines=$(printf '%s' "${CMDS}" | grep -c '^') -choice="$(printf '%s' "${CMDS}" | cut -d ' ' -f 1-2 | dmenu -c -i -l "${lines}")" || exit 1 + choice="$(printf '%s' "${CMDS}" | cut -d ' ' -f 1-2 | dmenu -c -i -l "${lines}")" || exit 1 -cmd="$(printf '%s\n' "${CMDS}" | grep "^${choice}[\s]*" | awk '{ $1=""; $2=""; print }' | sed 's/^[[:space:]]*//g')" + cmd="$(printf '%s\n' "${CMDS}" | grep -i "^${choice}[\s]*" | awk '{ $1=""; $2=""; print }' | sed 's/^[[:space:]]*//g')" -${cmd} + ${cmd} +} + +main "${@}" diff --git a/.local/bin/wm.sh b/.local/bin/wm.sh @@ -2,4 +2,6 @@ # # wm -while :; do "${WM}" >/dev/null 2>&1; done +main() { while :; do "${WM}" >/dev/null 2>&1; done ; } + +main "${@}" diff --git a/.local/bin/wp.sh b/.local/bin/wp.sh @@ -4,13 +4,13 @@ ALPHA=0.95 # wp is sym link -WP="${XDG_DATA_HOME:-${HOME}/.local/share}/wp" +WP="${XDG_DATA_HOME:-${HOME}/.local/share/}/wp" # 16 colors generated by pywal -COLORS="${XDG_CACHE_HOME:-${HOME}/.cache}/wal/colors.sh" +COLORS="${XDG_CACHE_HOME:-${HOME}/.cache/}/wal/colors.sh" # term fg DEFAULTFG=259 # xresources handles suckless vars -XRESOURCES="${XDG_CONFIG_HOME:-${HOME}/.config}/x/xresources" +XRESOURCES="${XDG_CONFIG_HOME:-${HOME}/.config/}/x/xresources" # get random valid file in dir get_rand_file() { @@ -25,7 +25,7 @@ get_rand_file() { while ! check_file "${file}"; do # get random file and remove it from list file="$(printf '%s' "${files}" | awk 'BEGIN{ srand() } { printf "%f %s\n", rand(), $0 }' | sort | cut -d ' ' -f 2 | head -n 1)" - files="$(printf '%s' "${files}" | grep -v "${file}")" + files="$(printf '%s' "${files}" | grep -iv "${file}")" # break if no more files to check [ -z "${files}" ] && break @@ -106,7 +106,7 @@ theme() { xrdb "${XRESOURCES}" # reload all instances of term - kill -s USR1 $(ps -ef | grep "\<${TERMINAL}\>" | grep -v '\<grep\>' | awk '{ printf "%s ", $2 }') + kill -s USR1 $(ps -ef | grep -i "\<${TERMINAL}\>" | grep -v '\<grep\>' | awk '{ printf "%s ", $2 }') # hacky work-around to change terminal fg on the fly # buggy with alpha diff --git a/.local/share/gnupg/gpg-agent.conf b/.local/share/gnupg/gpg-agent.conf @@ -0,0 +1,6 @@ +# cache for one year or until session ends +default-cache-ttl 31557600 +max-cache-ttl 31557600 + +# custom pinentry program +pinentry-program /home/mc/.local/bin/pin.sh