├── LICENSE ├── README.md └── mpdmenu /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2013-present Christopher Down 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Simple dmenu frontend for MPD. 2 | 3 | # Arguments 4 | 5 | Pass mpdmenu arguments first, followed by any dmenu arguments. They are separated by `::`. For example: 6 | 7 | mpdmenu -p :: -sb '#000000' 8 | 9 | `-l` is library mode (default), which descends artists and albums. `-p` is 10 | playlist mode, which selects a track from the current playlist. 11 | -------------------------------------------------------------------------------- /mpdmenu: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | all_name='[ALL]' 4 | mode=library 5 | 6 | d_artist() { 7 | mpc list artist | sort -f | dmenu -p artist "${dmenu_args[@]}" 8 | } 9 | 10 | d_album() { 11 | local artist="$1" 12 | local albums 13 | 14 | mapfile -t albums < <(mpc list album artist "$artist") 15 | if (( ${#albums[@]} > 1 )) ; then 16 | { 17 | printf '%s\n' "$all_name" 18 | printf '%s\n' "${albums[@]}" | sort -f 19 | } | dmenu -p album "${dmenu_args[@]}" 20 | else 21 | # We only have one album, so just use that. 22 | printf '%s\n' "${albums[0]}" 23 | fi 24 | } 25 | 26 | d_playlist() { 27 | local format="%position% %title%" 28 | local extra_format="(%artist% - %album%)" 29 | local track 30 | local num_extras 31 | 32 | # If all tracks are from the same artist and album, no need to display that 33 | num_extras=$(mpc playlist -f "$extra_format" | sort | uniq | wc -l) 34 | (( num_extras == 1 )) || format+=" $extra_format" 35 | 36 | track=$(mpc playlist -f "$format" | dmenu -p track "${dmenu_args[@]}") 37 | printf '%s' "${track%% *}" 38 | } 39 | 40 | i=2 41 | 42 | for arg do 43 | if [[ $arg == :: ]]; then 44 | dmenu_args=( "${@:$i}" ) 45 | break 46 | fi 47 | 48 | case "$arg" in 49 | -l) mode=library ;; 50 | -p) mode=playlist ;; 51 | esac 52 | 53 | let i++ 54 | done 55 | 56 | case "$mode" in 57 | library) 58 | artist=$(d_artist) 59 | [[ $artist ]] || exit 1 60 | 61 | album=$(d_album "$artist") 62 | [[ $album ]] || exit 2 63 | 64 | mpc clear 65 | if [[ $album == "$all_name" ]]; then 66 | mpc find artist "$artist" | sort | mpc add 67 | else 68 | mpc find artist "$artist" album "$album" | sort | mpc add 69 | fi 70 | 71 | mpc play >/dev/null 72 | ;; 73 | playlist) 74 | mpc play "$(d_playlist)" >/dev/null 75 | ;; 76 | esac 77 | --------------------------------------------------------------------------------