diff --git a/scripts/default.nix b/scripts/default.nix index 4b248fb..ee1d30f 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -29,6 +29,7 @@ create_scripts _thunar-terminal = [ final.terminal ]; kak-pager = [ fish final._diffr ]; kak-man-pager = [ final.kak-pager ]; + musmenu = [ mpc-cli final.wdmenu trash-cli libnotify sd wl-clipboard ]; showkeys = [ ]; # This will not work unless programs.wshowkeys is enabled systemwide terminal = [ alacritty ]; diff --git a/scripts/musmenu b/scripts/musmenu new file mode 100755 index 0000000..0fc2c31 --- /dev/null +++ b/scripts/musmenu @@ -0,0 +1,111 @@ +#!/bin/sh +set -e + +menu=wdmenu + +search() { + tabs 8 + + mpc playlist --format '%artist% : %title%@pos:%position%' | + sed '/^ : \t/d'| + column -ts"@" | + $menu | + grep -o 'pos:.*' | + cut -d: -f2 | + xargs -r mpc play +} + +get_current() { + music_root=$(xdg-user-dir MUSIC || echo "$HOME/Music") + current_file=$(mpc current -f %file%) + + echo "${music_root}/${current_file}" +} + +delete() { + current=$(get_current) + answer=$(printf "nothing\n$current" | $menu -p"delete?") + if test "$answer" = "$current"; then + trash "$answer" + mpc --quiet next + mpc --quiet update + + path=$(echo $answer | sd "$HOME" '~') + notify-send "Removed Music" "$path" + fi +} + +yank() { + current=$(get_current) + + # Some programs need you to pass a path, not the contents + wl-copy --type 'text/uri-list' "file:///${current}" + + notify-send "Yanked Music" "$(echo $current | sd "$HOME" "~")" +} + +padd() { + get_current + cd "$music_root" + choice=$(fd -E '*.lrc' -E '*.m3u8' | sort | $menu -p "Add Songs(Use Ctrl):") + mpc add "$choice" && + notify-send "Added Music" "$(echo $choice | sd "$HOME" "~")" || + notify-send "Failed to Add Music" "$(echo $choice | sd "$HOME" "~")" + mpdDup +} + +pclear() { + mpc clear && + notify-send "Cleared Playlist" || + notify-send "Failed Clear Playlist" +} + +psave() { + name=$(mpc playlist | $menu -p 'Save Playlist(Use Shift): ') + + mpc save "$name" && + notify-send "Created playlist" "$name" || + notify-send "Failed to Create Playlist" "$name" +} + +pload() { + name=$(mpc lsplaylists | $menu -p 'Load Playlist: ') + + mpc clear + mpc load "$name" && + notify-send "Loaded playlist" "$name" || + notify-send "Failed to Load Playlist" "$name" +} + +pdelete() { + name=$(mpc lsplaylists | $menu -p 'Delete Playlist: ') + + mpc delete "$name" && + notify-send "Deleted playlist" "$name" || + notify-send "Failed to Delete Playlist" "$name" +} + +usage() { + cmdname=$(basename "$0") + echo "Commands:" + echo " $cmdname search -- Search and play songs." + echo " $cmdname delete -- Prompt to delete the current song." + echo " $cmdname yank -- Copy current music to clipboard." + echo "Playlist Commands:" + echo " $cmdname padd -- Add song" + echo " $cmdname pclear -- Clear" + echo " $cmdname psave -- Save" + echo " $cmdname pload -- Load" + echo " $cmdname pdelete -- Delete" +} + +case "$1" in + delete | search | yank | padd | pclear | psave | pload | pdelete) + "$1" + ;; + *) + usage + test -n "$1" + echo "Unreconized option: $1" + ;; +esac diff --git a/user/mpd.nix b/user/mpd.nix index e87ed36..1c4a795 100644 --- a/user/mpd.nix +++ b/user/mpd.nix @@ -18,4 +18,7 @@ multimediaKeys = true; notifications = true; }; + home.packages = with pkgs; [ + musmenu + ]; } diff --git a/user/sway.nix b/user/sway.nix index 62e14d0..46d1e1e 100644 --- a/user/sway.nix +++ b/user/sway.nix @@ -151,8 +151,18 @@ in "q" = ""; "m" = "exec volumesh -t"; "s" = "exec ${pkgs.pulse_sink}/bin/pulse_sink"; + + "d" = "exec ${pkgs.musmenu}/bin/musmenu delete"; + "f" = "exec ${pkgs.musmenu}/bin/musmenu search"; + + "Shift+y" = "exec ${pkgs.musmenu}/bin/musmenu yank"; + "Ctrl+a" = "exec ${pkgs.musmenu}/bin/musmenu padd"; + "Ctrl+s" = "exec ${pkgs.musmenu}/bin/musmenu psave"; + "Ctrl+o" = "exec ${pkgs.musmenu}/bin/musmenu pload"; + "Ctrl+d" = "exec ${pkgs.musmenu}/bin/musmenu pdelete"; } // { "p" = "mode playerctl"; + "Ctrl+c" = "exec musmenu pclear"; }; playerctl = code_binds (return_mode {