shpotify icon indicating copy to clipboard operation
shpotify copied to clipboard

Options: Add an option to force non-colored output

Open rappazzo opened this issue 9 years ago • 10 comments

If the output is to be consumed by an application which does not handle formatted output, the script can be invoked with --no-color or -p to omit the formatting.

rappazzo avatar Feb 07 '16 13:02 rappazzo

Cool. Out of curiosity, what is this application you're trying to pipe the output to?

hnarayanan avatar Feb 08 '16 09:02 hnarayanan

Also, how does your usage of shift affect the order of you input flag?

hnarayanan avatar Feb 08 '16 09:02 hnarayanan

Out of curiosity, what is this application you're trying to pipe the output to?

I am running a fun little java program on a machine at work that plays sound clips, and does some text-to-speech from user input. We were also using the spotify app on it, and I wanted put the control in there. The way that I invoke the command in java is (for example):

new ProcessBuilder().command("sh", "-c", "spotify status").start();

Then I would read the result from the subprocess, and report back.


Also, how does your usage of shift affect the order of you input flag?

The intent of this patch is that you can only use the --no-color argument as the first argument. If the argument is present, then set the mode to be no-color and shift ARGV so that the rest of the command doesn't know about it.

I felt that this was the least intrusive way to add the flag. If you intend to add other arguments in the future, then perhaps a better approach would be to create a command array, then scan ARGV to populate the command array (status, play, etc). This would allow you to differentiate the flags from the commands.

rappazzo avatar Feb 08 '16 13:02 rappazzo

Cool, thank you for the explanation. I have not forgotten about this pull request (or the others), just mulling over how best to incorporate it.

hnarayanan avatar Feb 09 '16 11:02 hnarayanan

Still not forgotten!

I finally changed the syntax on the help in general to use <> for required params and [] for optional params. Now I'm one step closer to merging this, but will do so after some other odds and ends. 😺

hnarayanan avatar Sep 18 '16 20:09 hnarayanan

@hnarayanan Any chance of getting this merged soon? Since it'd be the first flag that the script supports, I don't see a problem doing it this way. A more robust way to do this would be with bash's built-in getopts functionality.

Edit: Also, since it seems you're busy with other projects, have you considered giving other users collaborator access to help you manage the project?

dkniffin avatar Apr 30 '18 16:04 dkniffin

I’m sorry, I don’t know how quick I can act on this (or anything else). I will get to it when I can.

hnarayanan avatar Apr 30 '18 17:04 hnarayanan

And I am sorry I was curt earlier. I am dealing with a lot of other stresses in life, and I reacted when even this project (which is supposed to be fun for me) became a place where I was expected to quickly act on something.

I really will get to it as soon as I can make the time to focus on this project again.

hnarayanan avatar May 28 '18 10:05 hnarayanan

And I only now saw your edit to the original comment. I will consider giving other people commit access, yes.

hnarayanan avatar May 28 '18 10:05 hnarayanan

I ran into the same coolers issue when using the script in a pipe. Here's what I did to test if the script is running in a terminal or not:

cecho(){
    if [ -t 1 ]
    then
        bold=$(tput bold);
        green=$(tput setaf 2);
        reset=$(tput sgr0);
        echo $bold$green"$1"$reset;
    else
        echo "$1"
    fi
}

frahugo avatar Mar 06 '21 22:03 frahugo