From f082d6c5a5abcf6575b5c6610d7b544a3434836c Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 20 Oct 2017 11:38:23 +0200 Subject: [PATCH] Cleaner async, music-client aliased to go trough awesome --- awesome/music.lua | 4 ++-- zsh/functions.zsh | 42 +++++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/awesome/music.lua b/awesome/music.lua index df09fdf..f401276 100644 --- a/awesome/music.lua +++ b/awesome/music.lua @@ -27,9 +27,9 @@ local function set_text(text) end end -ret.execute_command = function(command) +ret.execute_command = function(command, arg) - awful.spawn.easy_async('music-client ' .. command, function(stdout, stderr, reason, code) + awful.spawn.easy_async({'music-client', command, arg}, function(stdout, stderr, reason, code) local text = su.split(stdout, '\n') local active_command = diff --git a/zsh/functions.zsh b/zsh/functions.zsh index 08aef02..680f73d 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -112,17 +112,33 @@ if [ -d "$GCLONE_PATH" ]; then fi # Music things -# command -v music-server > /dev/null 2>&1 -# if [ $? -eq 0 ]; then -# mplayer() { -# ps -e | grep music-server > /dev/null 2>&1 -# if [ $? -ne 0 ]; then -# nohup music-server > /dev/null 2>&1 & -# disown -# sleep 0.2s -# fi -# filename=$(echo `realpath $1` | sed 's/ /\\\\ /g' | sed "s/'/\\\\\\\\'/g") -# awesome-client "require('music').execute_command('file ' .. \"$filename\")" -# } -# fi +command -v music-server > /dev/null 2>&1 +if [ $? -eq 0 ]; then + + # If music-server is installed, check if awesome is running with screenfetch + command -v screenfetch > /dev/null 2>&1 + + if [ $? -eq 0 ]; then + + screenfetch -d wm -nN | grep "Awesome" > /dev/null 2>&1 + + if [ $? -eq 0 ]; then + + # User is running awesome, music-client will go through awesome-client + music-client() { + command=$1 + if [ $# -eq 1 ]; then + echo "require('music').execute_command(\"$command\")" + else + library_path=$(realpath $2 | rev | cut -d '/' -f -3 | rev) + awesome_command="require('music').execute_command(\"$command\",\"$library_path\")" + echo $awesome_command | awesome-client + fi + } + + fi + + fi + +fi