diff --git a/rofi-mpd b/rofi-mpd index 36f45cb..bf281ed 100644 --- a/rofi-mpd +++ b/rofi-mpd @@ -5,62 +5,63 @@ ESC_ACTION="break" # source configuration file for rofi if exists -ROFI="rofi -dmenu -p 'Search:'" +ROFI="rofi -dmenu -i -p 'Search:'" +PORT=6600 addaftercurrent(){ #playlist is empty, just add the song - if [ "$(mpc -p 6601 playlist | wc -l)" == "0" ]; then - mpc -p 6601 add "$1" + if [ "$(mpc -p $PORT playlist | wc -l)" == "0" ]; then + mpc -p $PORT add "$1" #there is no current song so mpd is stopped #it seems to be impossible to determine the current songs' position when #mpd is stopped, so just add to the end - elif [ -z "$(mpc -p 6601 current)" ]; then - mpc -p 6601 play - CUR_POS=$(mpc -p 6601 | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}') - END_POS=$(mpc -p 6601 playlist | wc -l) - mpc -p 6601 add "$1" - mpc -p 6601 move $(($END_POS+1)) $(($CUR_POS+1)) - mpc -p 6601 stop + elif [ -z "$(mpc -p $PORT current)" ]; then + mpc -p $PORT play + CUR_POS=$(mpc -p $PORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}') + END_POS=$(mpc -p $PORT playlist | wc -l) + mpc -p $PORT add "$1" + mpc -p $PORT move $(($END_POS+1)) $(($CUR_POS+1)) + mpc -p $PORT stop #at least 1 song is in the playlist, determine the position of the #currently played song and add $1 after it else - CUR_POS=$(mpc -p 6601 | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}') - END_POS=$(mpc -p 6601 playlist | wc -l) - mpc -p 6601 add "$1" - mpc -p 6601 move $(($END_POS+1)) $(($CUR_POS+1)) + CUR_POS=$(mpc -p $PORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}') + END_POS=$(mpc -p $PORT playlist | wc -l) + mpc -p $PORT add "$1" + mpc -p $PORT move $(($END_POS+1)) $(($CUR_POS+1)) fi } addaftercurrentandplay(){ #playlist is empty, just add the song - if [ "$(mpc -p 6601 playlist | wc -l)" == "0" ]; then - mpc -p 6601 add "$1" - mpc -p 6601 play + if [ "$(mpc -p $PORT playlist | wc -l)" == "0" ]; then + mpc -p $PORT add "$1" + mpc -p $PORT play #there is no current song so mpd is stopped #it seems to be impossible to determine the current songs' position when #mpd is stopped, so just add to the end - elif [ -z "$(mpc -p 6601 current)" ]; then - mpc -p 6601play - CUR_POS=$(mpc -p 6601 | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}') - END_POS=$(mpc -p 6601 playlist | wc -l) - mpc -p 6601 add "$1" - mpc -p 6601 move $(($END_POS+1)) $(($CUR_POS+1)) - mpc -p 6601 play $(($CUR_POS+1)) + elif [ -z "$(mpc -p $PORT current)" ]; then + mpc -p $PORTplay + CUR_POS=$(mpc -p $PORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}') + END_POS=$(mpc -p $PORT playlist | wc -l) + mpc -p $PORT add "$1" + mpc -p $PORT move $(($END_POS+1)) $(($CUR_POS+1)) + mpc -p $PORT play $(($CUR_POS+1)) #at least 1 song is in the playlist, determine the position of the #currently played song and add $1 after it else - CUR_POS=$(mpc -p 6601 | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}') - END_POS=$(mpc -p 6601 playlist | wc -l) - mpc -p 6601 add "$1" - mpc -p 6601 move $(($END_POS+1)) $(($CUR_POS+1)) - mpc -p 6601 play $(($CUR_POS+1)) + CUR_POS=$(mpc -p $PORT | tail -2 | head -1 | awk '{print $2}' | sed 's/#//' | awk -F/ '{print $1}') + END_POS=$(mpc -p $PORT playlist | wc -l) + mpc -p $PORT add "$1" + mpc -p $PORT move $(($END_POS+1)) $(($CUR_POS+1)) + mpc -p $PORT play $(($CUR_POS+1)) fi } @@ -70,39 +71,39 @@ case $1 in while true; do - ARTIST="$(mpc -p 6601 list artist | sort -f | $ROFI)"; + ARTIST="$(mpc -p $PORT list artist | sort -f | $ROFI)"; if [ "$ARTIST" = "" ]; then $ESC_ACTION; fi while true; do - ALBUMS=$(mpc -p 6601 list album artist "$ARTIST" | sort -f); + ALBUMS=$(mpc -p $PORT list album artist "$ARTIST" | sort -f); ALBUM=$(echo -e "replace all\nadd all\n--------------------------\n$ALBUMS" | $ROFI); if [ "$ALBUM" = "" ]; then $ESC_ACTION; elif [ "$ALBUM" = "replace all" ]; then - CUR_SONG=$(mpc -p 6601 current) - mpc -p 6601 clear - mpc -p 6601 find artist "$ARTIST" | mpc -p 6601 add - if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi + CUR_SONG=$(mpc -p $PORT current) + mpc -p $PORT clear + mpc -p $PORT find artist "$ARTIST" | mpc -p $PORT add + if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi $ESC_ACTION elif [ "$ALBUM" = "add all" ]; then - mpc -p 6601 find artist "$ARTIST" | mpc -p 6601 add + mpc -p $PORT find artist "$ARTIST" | mpc -p $PORT add $ESC_ACTION fi while true; do - TITLES=$(mpc -p 6601 list title artist "$ARTIST" album "$ALBUM") + TITLES=$(mpc -p $PORT list title artist "$ARTIST" album "$ALBUM") TITLE=$(echo -e "replace all\nadd all\n--------------------------\n$TITLES" | $ROFI); if [ "$TITLE" = "" ]; then $ESC_ACTION elif [ "$TITLE" = "replace all" ]; then - CUR_SONG=$(mpc -p 6601 current) - mpc -p 6601 clear; - mpc -p 6601 find artist "$ARTIST" album "$ALBUM" | mpc -p 6601 add - if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi + CUR_SONG=$(mpc -p $PORT current) + mpc -p $PORT clear; + mpc -p $PORT find artist "$ARTIST" album "$ALBUM" | mpc -p $PORT add + if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi $ESC_ACTION elif [ "$TITLE" = "add all" ]; then - mpc -p 6601 find artist "$ARTIST" album "$ALBUM" | mpc -p 6601 add + mpc -p $PORT find artist "$ARTIST" album "$ALBUM" | mpc -p $PORT add $ESC_ACTION fi @@ -116,22 +117,22 @@ case $1 in ;; "add after current and play") - addaftercurrentandplay "$(mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )" + addaftercurrentandplay "$(mpc -p $PORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )" ;; "add after current") - addaftercurrent "$(mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )" + addaftercurrent "$(mpc -p $PORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 )" ;; "replace") - CUR_SONG=$(mpc -p 6601 current) - mpc -p 6601 clear - mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p 6601 add - if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi + CUR_SONG=$(mpc -p $PORT current) + mpc -p $PORT clear + mpc -p $PORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p $PORT add + if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi ;; "add at the end") - mpc -p 6601 find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p 6601 add + mpc -p $PORT find artist "$ARTIST" album "$ALBUM" title "$TITLE" | head -1 | mpc -p $PORT add ;; esac @@ -144,51 +145,51 @@ case $1 in -t|--track) - TITLE=$(mpc -p 6601 list title | sort -f | $ROFI) + TITLE=$(mpc -p $PORT list title | sort -f | $ROFI) if [ "$TITLE" = "" ]; then exit; fi - SONG=$(mpc -p 6601 find title "$TITLE" | head -1) + SONG=$(mpc -p $PORT find title "$TITLE" | head -1) addaftercurrentandplay "$SONG" ;; -p|--playlist) - PLAYLIST=$(mpc -p 6601 lsplaylists | $ROFI); + PLAYLIST=$(mpc -p $PORT lsplaylists | $ROFI); if [ "$PLAYLIST" = "" ]; then exit; fi - CUR_SONG=$(mpc -p 6601 current) - mpc -p 6601 clear - mpc -p 6601 load "$PLAYLIST"; - if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi + CUR_SONG=$(mpc -p $PORT current) + mpc -p $PORT clear + mpc -p $PORT load "$PLAYLIST"; + if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi ;; -j|--jump) - TITLE=$(mpc -p 6601 playlist | $ROFI); + TITLE=$(mpc -p $PORT playlist | $ROFI); if [ "$TITLE" = "" ]; then exit; fi - POS=$(mpc -p 6601 playlist | grep -n "$TITLE" | awk -F: '{print $1}') - mpc -p 6601 play $POS; + POS=$(mpc -p $PORT playlist | grep -n "$TITLE" | awk -F: '{print $1}') + mpc -p $PORT play $POS; ;; -l|--longplayer) while true; do - ALBUM=$(mpc -p 6601 list album | sort -f | $ROFI); + ALBUM=$(mpc -p $PORT list album | sort -f | $ROFI); if [ "$ALBUM" = "" ]; then $ESC_ACTION; fi while true; do - TITLES=$(mpc -p 6601 list title album "$ALBUM") + TITLES=$(mpc -p $PORT list title album "$ALBUM") TITLE=$(echo -e "replace all\nadd all\n--------------------------\n$TITLES" | $ROFI); if [ "$TITLE" = "" ]; then $ESC_ACTION elif [ "$TITLE" = "replace all" ]; then - CUR_SONG=$(mpc -p 6601 current) - mpc -p 6601 clear; - mpc -p 6601 find album "$ALBUM" | mpc -p 6601 add - if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi + CUR_SONG=$(mpc -p $PORT current) + mpc -p $PORT clear; + mpc -p $PORT find album "$ALBUM" | mpc -p $PORT add + if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi $ESC_ACTION elif [ "$TITLE" = "add all" ]; then - mpc -p 6601 find album "$ALBUM" | mpc -p 6601 add + mpc -p $PORT find album "$ALBUM" | mpc -p $PORT add $ESC_ACTION fi @@ -202,22 +203,22 @@ case $1 in ;; "add after current and play") - addaftercurrentandplay "$(mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 )" + addaftercurrentandplay "$(mpc -p $PORT find album "$ALBUM" title "$TITLE" | head -1 )" ;; "add after current") - addaftercurrent "$(mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 )" + addaftercurrent "$(mpc -p $PORT find album "$ALBUM" title "$TITLE" | head -1 )" ;; "replace") - CUR_SONG=$(mpc -p 6601 current) - mpc -p 6601 clear - mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 | mpc -p 6601 add - if [ -n "$CUR_SONG" ]; then mpc -p 6601 play; fi + CUR_SONG=$(mpc -p $PORT current) + mpc -p $PORT clear + mpc -p $PORT find album "$ALBUM" title "$TITLE" | head -1 | mpc -p $PORT add + if [ -n "$CUR_SONG" ]; then mpc -p $PORT play; fi ;; "add at the end") - mpc -p 6601 find album "$ALBUM" title "$TITLE" | head -1 | mpc -p 6601 add + mpc -p $PORT find album "$ALBUM" title "$TITLE" | head -1 | mpc -p $PORT add ;; esac