Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options: Add an option to force non-colored output #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rappazzo
Copy link

@rappazzo rappazzo commented Feb 7, 2016

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.

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.
@hnarayanan
Copy link
Owner

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

@hnarayanan
Copy link
Owner

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

@rappazzo
Copy link
Author

rappazzo commented Feb 8, 2016

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.

@hnarayanan
Copy link
Owner

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
Copy link
Owner

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 hnarayanan added this to the 1.3 milestone Sep 18, 2016
@hnarayanan hnarayanan self-assigned this Sep 18, 2016
@dkniffin
Copy link
Contributor

dkniffin commented Apr 30, 2018

@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?

@hnarayanan
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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

@frahugo
Copy link

frahugo commented Mar 6, 2021

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants