Earlier quoted context omitted.
In case someone wonders, this does retain the repeated "+" to indicate call depth: "The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection." -- this is an important feature when working on large-ish (1-10+k LoC) scripts, which end up having very deep call stacks and a flat trace output would be completely inscrutable.
If you have 10k LoC Bash scripts, then you’ve got bigger problems!
Bash PS1 Generator
131–140 of 146 posts
Re: Bash PS1 Generator
#132I built one in 2012 http://xta.github.io/HalloweenBash/ with drag and drop.
I think there is room for someone to create a site to generate PS1 for zsh (since macOS comes with zsh now).
Re: Bash PS1 Generator
#133Re: Bash PS1 Generator
#134Am I the only one who leaves mine as is?
Re: Bash PS1 Generator
#135On the site all prompt variables end in "tput sgr0". I haven't seen that before. What does that do and why is it needed?
Save and Restore cursor doesn't always work because I don't necessarily need the vertical position restored, for example:
ls_color () {
tput sc;
/bin/ls --color=auto "$@";
push_cursor_position;
tput rc;
pop_cursor_position
}Re: Bash PS1 Generator
#136Seeing '>' as an option makes it somewhat relevant to mention here: I'd recommend not ending your prompt with a '>' character (as you'd see in DOS/Windows a lot, which might make it seem like a nice option). If you accidentally copy and paste your prompt with a command after it, (which is easy to do with a couple mouse clicks, or if you forget what's in your clipboard after copying some lines from your terminal,) the…
I just copy paste my session, and rerun most commands.
Re: Bash PS1 Generator
#137Additionally, I have used git-prompt as PROMPT_COMMAND for a long time, and it's certainly the most useful piece of information.
Re: Bash PS1 Generator
#138I've been using this for years (output of 'echo $PS1' ): [\e[1;33m\u\e[1;32m@\e[1;31m\H \e[1;36m\t\e[0m] [\e[1;35m\w\e[0m](\e[1;32m\#\e[0m )\n$ which presents as: [User@HOST 10:21:07][~](2) $ (Username, hostname, 24 hour local time, CWD, history count, newline, prompt) More detail from my .bashrc: # Define some colors first: red='\e[0;31m' RED='\e[1;31m' blue='\e[0;34m' BLUE='\e[1;34m' cyan='\e[0;36m' CYAN='\e[1;36m'…
Re: Bash PS1 Generator
#139I was moved to experiment with Fish shell one day, and wanted to see how to set my prompt. Answer: you create a function named `fish_prompt` that uses regular shell commands like `echo` (and fish's own `set_color`) to imperatively build the prompt. Want to make a right-hand prompt for something like the current time? Write a function named `fish_right_prompt`. For example, here's mine: function fish_right_prompt --de…
Re: Bash PS1 Generator
#140I was moved to experiment with Fish shell one day, and wanted to see how to set my prompt. Answer: you create a function named `fish_prompt` that uses regular shell commands like `echo` (and fish's own `set_color`) to imperatively build the prompt. Want to make a right-hand prompt for something like the current time? Write a function named `fish_right_prompt`. For example, here's mine: function fish_right_prompt --de…
Note that in bash there is the PROMPT_COMMAND variable, which runs before the prompt is printed and which can be used to print things and to set PS1 if you want more dynamism than bash more directly affords.