Slackadays/Clipboard

No progress when piping output.

useredsa opened this issue · 3 comments

Is your feature request related to a problem? Please describe.

When using cb to output the copied text to the terminal (cb | cat, for instance), the error output, which contains messages such as the following, is written at the same time as the output from the cat command and the output cannot be seen.

Example:

~ $ cb | cat
⬤ Setting up... %?, 0s elapsed █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒    
 ✔  Pasted 5B
~ $ 

Describe the solution you'd like

I suggest that the human-readable information messages are not printed when piping the output to another command. Only error messages.

Describe alternatives you've considered

I know you can use 2> /dev/null or --no-progress, but it is inconvenient. Furthermore, the progress commands do not seem to offer relevant information in most cases.

fixed in 5606f1b, now cb will wait 500ms to display a progress bar (so quick invocations lack that ugly message, and longer ones will still display progress)

I suggest that the human-readable information messages are not printed when piping the output to another command. Only error messages.

@Slackadays What did you think of this?

@useredsa displaying human-readable information messages is like one of the whole reasons why CB exists. therefore, it's probably not going to be disabled by default anytime soon. there is also currently no facility in CB that disables messages just for pipes. however, I know that this conclusion is unsatisfying, and so here is a clever little shell function that implements exactly what you wanted:

cb() {
        if [ ! -t 0 ] || [ ! -t 1 ] || [ ! -t 2 ]; then
                CLIPBOARD_SILENT=1 command cb "$@"
        else
                command cb "$@"
        fi
}
here's how it works
  1. first check if we are in a pipe situation by checking if stdin, stdout, or stderr are not ttys

  2. if we are in a pipe, then disable all non-error messages and run the cb binary using any given arguments

  3. otherwise, run the cb binary with any given arguments

just add it to your shell/Bash prompt, and now CB will only show error messages for pipes!

espero que esto te ayude :)