dots

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

commit 46f06be448ddcffdaf1d328238074fa314b4c6bd
parent 906e1a8c076564e54a145e965d1c1fcd42644943
Author: Matthew Carlson <matt@mcarlson.xyz>
Date:   Sun,  1 Aug 2021 02:06:42 -0400

added some bar scripts

Diffstat:
M.config/sh/profile | 2+-
M.config/x/xprofile | 1+
A.local/bin/bar/date.sh | 7+++++++
A.local/bin/bar/monitor.sh | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
A.local/bin/bar/music.sh | 46++++++++++++++++++++++++++++++++++++++++++++++
A.local/bin/bar/time.sh | 7+++++++
A.local/bin/bar/vol.sh | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 183 insertions(+), 1 deletion(-)

diff --git a/.config/sh/profile b/.config/sh/profile @@ -15,7 +15,7 @@ export BROWSER='brave' export TERMINAL='st' export FILE_VIEWER='fff' export EDITOR='vim' -export MUSIC_PLAYER='cmus' +export MUSIC_PLAYER='ncmpcpp' export MAIL_CLIENT='neomutt' export MEDIA_PLAYER='mpv' export READER='zathura' diff --git a/.config/x/xprofile b/.config/x/xprofile @@ -8,3 +8,4 @@ lock.sh & feh --no-fehbg --bg-scale "${XDG_DATA_HOME:-${HOME}/.local/share}/wp" xcompmgr & xset r rate 250 50 +mpd & diff --git a/.local/bin/bar/date.sh b/.local/bin/bar/date.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# +# date + +ICON='' + +printf '%s\n' "${ICON} $(date +%a,\ %Y-%m-%d)" diff --git a/.local/bin/bar/monitor.sh b/.local/bin/bar/monitor.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# +# monitor + +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" + +get_brightness() { + [ ! -f "${BRIGHTNESS}" ] && return + # brightness cache should contain only number + ! brightness=$(cat ${BRIGHTNESS} | grep '^[0-9][0-9]*$') && return + +} + +set_brightness() { + get_brightness + + # keep between 0-100 + [ "${1}" = '+' ] && [ ${brightness} -ge 100 ] && return + [ "${1}" = '-' ] && [ ${brightness} -le 0 ] && return + + brightness=$((${brightness} ${1} ${2})) + + # set brightness using ddcutil + doas ddcutil setvcp ${VCP_CODE} ${brightness} >/dev/null 2>&1 + + # 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() { + get_brightness + printf '%s\n' "${ICON} ${brightness}%" +} + +main() { + # called from bar + [ ${#} -eq 0 ] && show + + # bar options + case "${BLOCK_BUTTON}" in + 4) set_brightness + 25 ;; + 5) set_brightness - 25 ;; + esac + + # set monitor brightness based on args + # ${1} = +/- and ${2} = percentage + [ "${*}" ] && set_brightness "${1}" "${2}" +} + +main "${@}" diff --git a/.local/bin/bar/music.sh b/.local/bin/bar/music.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# +# music + +MUSIC_ICON='' +PLAYING_ICON='' +PAUSED_ICON='' + +open() { "${TERMINAL}" -c "${MUSIC_PLAYER}" -e "${MUSIC_PLAYER}" ; } + +show() { + # get current song name + song="$(mpc -f %title% | head -n 1)" + # get state of song + stat="$(mpc -f %title% | sed '2q;d' | awk '{ print $1 }' | tr -d '[:punct:]')" + + # no songs + [ -z "${stat}" ] && printf '%s\n' "${MUSIC_ICON}" + # song is playing + [ "${stat}" = 'playing' ] && printf '%s\n' "${PLAYING_ICON} ${song}" + # paused + [ "${stat}" = 'paused' ] && printf '%s\n' "${PAUSED_ICON} ${song}" +} + +main() { + # called from bar + [ ${#} -eq 0 ] && show + + # bar options + case "${BLOCK_BUTTON}" in + 1) open ;; + 2) mpc -q toggle ;; + 4) mpc -q prev ;; + 5) [ -n "$( mpc -f %title% queue)" ] && mpc -q next ;; + esac + + while getopts 'o' opt; do + case "${opt}" in + # open music player if called with o flag + o) open ;; + *) return ;; + esac + done +} + +main "${@}" diff --git a/.local/bin/bar/time.sh b/.local/bin/bar/time.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# +# time + +ICON='' + +printf '%s\n' "${ICON} $(date +%I:%M\ %p)" diff --git a/.local/bin/bar/vol.sh b/.local/bin/bar/vol.sh @@ -0,0 +1,67 @@ +#!/bin/sh +# +# vol + +VOLUME_HIGH_ICON='' +VOLUME_MID_ICON='' +VOLUME_LOW_ICON='' +VOLUME_OFF_ICON='' +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' + fi +} + +get_vol() { amixer get "${scontrol}" -M | grep '\[[0-9][0-9]*\%\]' | awk '{ print $5 }' | head -n 1 | tr -d '[:punct:]' ; } + +toggle() { + [ "${scontrol}" = 'Master' ] && amixer set "${scontrol}" toggle + [ "${scontrol}" = 'PCM' ] && amixer set 'IEC958,5' toggle +} + +# set volume linearly +set_vol() { amixer set "${scontrol}" "${2}"%"${1}" -M ; } + +show() { + 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 + 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}%" ;; + esac +} + +main() { + get_scontrol + + # called from bar + [ ${#} -eq 0 ] && show + + # bar options + 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 + # ${1} = +/- and ${2} = percentage + [ "${*}" ] && set_vol "${1}" "${2}" +} + +main "${@}"