dots

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

commit e6bb52b09e1a0a280305468fa0e7ab10a14e4284
parent 74187b99da074c517d28c3ac26d3f232cbc6e546
Author: Matthew Carlson <matt@mcarlson.xyz>
Date:   Wed, 18 Aug 2021 00:38:31 -0400

added toggle function to music script; xmenu now supports emojis

Diffstat:
M.config/x/xresources | 2+-
M.local/bin/bar/music.sh | 34+++++++++++++++++++++++++++-------
M.local/bin/compile.sh | 2+-
3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/.config/x/xresources b/.config/x/xresources @@ -153,5 +153,5 @@ xmenu.selbackground : col2 xmenu.selforeground : col0 xmenu.separator : col7 xmenu.border : col2 -xmenu.font : monospace:size=16,Font Awesome 5 Pro Solid:size=16 +xmenu.font : monospace:size=16,Font Awesome 5 Pro Solid:size=16,Noto Color Emoji:size=16 xmenu.alignment : LeftAlignment diff --git a/.local/bin/bar/music.sh b/.local/bin/bar/music.sh @@ -8,18 +8,37 @@ PAUSED_ICON='' open() { "${TERMINAL}" -c "${MUSIC_PLAYER}" -e "${MUSIC_PLAYER}" ; } -bar() { +get_song_and_state() { # 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:]')" + state="$(mpc -f %title% | sed '2q;d' | awk '{ print $1 }' | tr -d '[:punct:]')" +} + +toggle() { + # pause if playing and play if paused + mpc -q toggle + + get_song_and_state + + # convert first letter of state from lowercase to uppercase + first_letter="$(printf '%s\n' "${state}" | cut -c 1 | tr '[:lower:]' '[:upper:]')" + rest="$(printf '%s\n' "${state}" | cut -c 2-)" + state="${first_letter}${rest}" + + env HERBE_ID=/0 herbe "${state} ${song}" & +} + + +bar() { + get_song_and_state # no songs - [ -z "${stat}" ] && printf '%s\n' "${MUSIC_ICON}" + [ -z "${state}" ] && printf '%s\n' "${MUSIC_ICON}" # song is playing - [ "${stat}" = 'playing' ] && printf '%s\n' "${PLAYING_ICON} ${song}" + [ "${state}" = 'playing' ] && printf '%s\n' "${PLAYING_ICON} ${song}" # paused - [ "${stat}" = 'paused' ] && printf '%s\n' "${PAUSED_ICON} ${song}" + [ "${state}" = 'paused' ] && printf '%s\n' "${PAUSED_ICON} ${song}" } main() { @@ -29,15 +48,16 @@ main() { # bar usage case ${BLOCK_BUTTON} in 1) open ;; - 2) mpc -q toggle ;; + 2) toggle ;; 4) mpc -q prev ;; 5) [ -n "$( mpc -f %title% queue)" ] && mpc -q next ;; esac - while getopts 'o' opt; do + while getopts 'ot' opt; do case "${opt}" in # open music player if called with o flag o) open ;; + t) toggle ;; *) return ;; esac done diff --git a/.local/bin/compile.sh b/.local/bin/compile.sh @@ -38,7 +38,7 @@ main() { # different compile options based on file extension case "${ext}" in - # GNU compilers + # GNU compilers 'c') cc "${file}" -o "${base}" && "${base}" ;; 'cpp') g++ "${file}" -o "${base}" && "${base}" ;; 'java') javac "${file}" && java "${file}" ;;