add color echo

This commit is contained in:
mahi97 2016-08-31 03:56:21 +04:30
parent 92586e38c7
commit 2a5321f4e6

View file

@ -291,9 +291,16 @@ function spotify() {
echo " toggle repeat # Toggles repeat playback mode."; echo " toggle repeat # Toggles repeat playback mode.";
} }
cecho(){
bold=$(tput bold);
green=$(tput setaf 2);
reset=$(tput sgr0);
echo "$bold$green$1$reset";
}
showStatus () { showStatus () {
state=$(osascript -e 'tell application "Spotify" to player state as string'); state=$(osascript -e 'tell application "Spotify" to player state as string');
echo "Spotify is currently $state."; cecho "Spotify is currently $state.";
if [ "$state" = "playing" ]; then if [ "$state" = "playing" ]; then
artist=$(osascript -e 'tell application "Spotify" to artist of current track as string'); artist=$(osascript -e 'tell application "Spotify" to artist of current track as string');
album=$(osascript -e 'tell application "Spotify" to album of current track as string'); album=$(osascript -e 'tell application "Spotify" to album of current track as string');
@ -307,6 +314,8 @@ function spotify() {
fi fi
} }
if [ $# = 0 ]; then if [ $# = 0 ]; then
showHelp; showHelp;
else else
@ -321,50 +330,50 @@ function spotify() {
case $arg in case $arg in
"play" ) "play" )
echo "Playing Spotify."; cecho "Playing Spotify.";
osascript -e 'tell application "Spotify" to play'; osascript -e 'tell application "Spotify" to play';
break ;; break ;;
"pause" ) "pause" )
echo "Pausing Spotify."; cecho "Pausing Spotify.";
osascript -e 'tell application "Spotify" to pause'; osascript -e 'tell application "Spotify" to pause';
break ;; break ;;
"quit" ) "quit" )
echo "Quitting Spotify."; cecho "Quitting Spotify.";
osascript -e 'tell application "Spotify" to quit'; osascript -e 'tell application "Spotify" to quit';
exit 1 ;; exit 1 ;;
"next" ) "next" )
echo "Going to next track." ; cecho "Going to next track." ;
osascript -e 'tell application "Spotify" to next track'; osascript -e 'tell application "Spotify" to next track';
break ;; break ;;
"prev" ) "prev" )
echo "Going to previous track."; cecho "Going to previous track.";
osascript -e 'tell application "Spotify" to previous track'; osascript -e 'tell application "Spotify" to previous track';
break ;; break ;;
"vol" ) "vol" )
vol=$(osascript -e 'tell application "Spotify" to sound volume as integer'); vol=$(osascript -e 'tell application "Spotify" to sound volume as integer');
if [[ "$2" = "show" || "$2" = "" ]]; then if [[ "$2" = "show" || "$2" = "" ]]; then
echo "Current Spotify volume level is $vol."; cecho "Current Spotify volume level is $vol.";
break ; break ;
elif [ "$2" = "up" ]; then elif [ "$2" = "up" ]; then
if [ "$vol" -le 90 ]; then if [ "$vol" -le 90 ]; then
newvol=$(( vol+10 )); newvol=$(( vol+10 ));
echo "Increasing Spotify volume to $newvol."; cecho "Increasing Spotify volume to $newvol.";
else else
newvol=100; newvol=100;
echo "Spotify volume level is at max."; cecho "Spotify volume level is at max.";
fi fi
elif [ "$2" = "down" ]; then elif [ "$2" = "down" ]; then
if [ "$vol" -ge 10 ]; then if [ "$vol" -ge 10 ]; then
newvol=$(( vol-10 )); newvol=$(( vol-10 ));
echo "Reducing Spotify volume to $newvol."; cecho "Reducing Spotify volume to $newvol.";
else else
newvol=0; newvol=0;
echo "Spotify volume level is at min."; cecho "Spotify volume level is at min.";
fi fi
elif [ "$2" -ge 0 ]; then elif [ "$2" -ge 0 ]; then
newvol=$2; newvol=$2;
@ -377,16 +386,16 @@ function spotify() {
if [ "$2" = "shuffle" ]; then if [ "$2" = "shuffle" ]; then
osascript -e 'tell application "Spotify" to set shuffling to not shuffling'; osascript -e 'tell application "Spotify" to set shuffling to not shuffling';
curr=$(osascript -e 'tell application "Spotify" to shuffling'); curr=$(osascript -e 'tell application "Spotify" to shuffling');
echo "Spotify shuffling set to $curr"; cecho "Spotify shuffling set to $curr";
elif [ "$2" = "repeat" ]; then elif [ "$2" = "repeat" ]; then
osascript -e 'tell application "Spotify" to set repeating to not repeating'; osascript -e 'tell application "Spotify" to set repeating to not repeating';
curr=$(osascript -e 'tell application "Spotify" to repeating'); curr=$(osascript -e 'tell application "Spotify" to repeating');
echo "Spotify repeating set to $curr"; cecho "Spotify repeating set to $curr";
fi fi
break ;; break ;;
"pos" ) "pos" )
echo "Adjusting Spotify play position." cecho "Adjusting Spotify play position."
osascript -e "tell application \"Spotify\" to set player position to $2"; osascript -e "tell application \"Spotify\" to set player position to $2";
break;; break;;
@ -431,8 +440,8 @@ function spotify() {
remove='spotify:track:' remove='spotify:track:'
url=${url#$remove} url=${url#$remove}
url="http://open.spotify.com/track/$url" url="http://open.spotify.com/track/$url"
echo "Share URL: $url"; cecho "Share URL: $url";
echo -n "$url" | pbcopy cecho -n "$url" | pbcopy
break;; break;;
-h|--help| *) -h|--help| *)