twolfson / sexy-bash-prompt

Bash prompt with colors, git statuses, and git branches.
MIT License
1.14k stars 155 forks source link

sexy-bash-prompt and 'set -x' #48

Closed rpdelaney closed 6 years ago

rpdelaney commented 9 years ago

set -x is a familiar shell option for debugging. Usually, I like to set it from the command-line before running a script to debug, as is common practice. But this causes lots of unwanted debugging output from sexy-bash-prompt because the functions it invokes also return debugging output.

Would it be reasonable to add a handler to each function that checks for this flag, disables it, and then restores it before exit? I could submit a pull request to that effect.

twolfson commented 9 years ago

It feels like this is not the responsibility of sexy-bash-prompt. Why are you setting a global set -x flag? Is there a problem with setting it inside your script?

For what it's worth, if someone is setting a global flag, then they might actually want debug output from sexy-bash-prompt as well as everything else.

rpdelaney commented 9 years ago

Setting it inside the script is not a 'problem', per se: it's just inconvenient.

For people who want to debug the prompt, I suppose we could support another env var like SEXY_BASH_PROMPT_DEBUG. Or they could edit the script ;)

twolfson commented 9 years ago

Yea, but that feels like we are adding more workarounds to the problem.

I added a set -x to my terminal and only saw 2 invocations:

selection_006

Then, I moved my prompt to use these set +x flags:

# Define the sexy-bash-prompt
PS1="\[$sexy_bash_prompt_user_color\]\u\[$sexy_bash_prompt_reset\] \
\[$sexy_bash_prompt_preposition_color\]at\[$sexy_bash_prompt_reset\] \
\[$sexy_bash_prompt_device_color\]\h\[$sexy_bash_prompt_reset\] \
\[$sexy_bash_prompt_preposition_color\]in\[$sexy_bash_prompt_reset\] \
\[$sexy_bash_prompt_dir_color\]\w\[$sexy_bash_prompt_reset\]\
\$(set +x && sexy_bash_prompt_is_on_git && \
  echo -n \" \[$sexy_bash_prompt_preposition_color\]on\[$sexy_bash_prompt_reset\] \" && \
  echo -n \"\[$sexy_bash_prompt_git_status_color\]\$(sexy_bash_prompt_get_git_info)\" && \
  echo -n \"\[$sexy_bash_prompt_git_progress_color\]\$(sexy_bash_prompt_get_git_progress)\" && \
  echo -n \"\[$sexy_bash_prompt_preposition_color\]\")\n\[$sexy_bash_prompt_reset\]\
\[$sexy_bash_prompt_symbol_color\]$(set +x && sexy_bash_prompt_get_prompt_symbol) \[$sexy_bash_prompt_reset\]"

But there are still echos coming from the prompt.

selection_007

twolfson commented 9 years ago

Ah, never mind. I went into a git directory and now see al the noise.

twolfson commented 9 years ago

I did some research but am going to step away for a bit. New info I found out:

(all info via man bash)

twolfson commented 9 years ago

Alright, back. I am still on the fence about this. Can we research what other libraries do for this scenario?

rpdelaney commented 9 years ago

I'm looking into it.

abhijit86k commented 7 years ago

When I need to run anything with +x I run it like this: $ set -x; comand -arg1 -arg2 -arg3; set +x;

clean terminal again.

rpdelaney commented 6 years ago

Yeah good enough for me.