1

In-short: would like prompt to appear faster, although it's not sluggish.

Making a custom prompt for my bash terminal; the following list is in my /etc/bash.bashrc

I already use the "gitstatus" repo, which speeds up certain git commands. I think slowdowns come from the number of commands themselves. I want to know if I can generally use LESS git commands to do the same thing.

Here is a list of everything I do:

  1. Obtain branch (if head detached, commands requiring it skipped)
  2. Check for upstream
  3. git rev-list --left-right --count "$branch"..."$upstream" to check if ahead or behind
  4. Check for stashes

EDIT: Disregard #5. I called command #8 first, obtained this information, and appended #5 to PS1 before command #8

  1. Check for dirty branch (done separately; I know #8 provides this info, but this command is called earlier on, and I like the symbol there)

  2. Check for remote

  3. Check for untracked files (separately than the bullet below, as they are located early in the prompt as I treat them as a higher priority "problem")

  4. All at once check for modified, added, removes, or unmerged files by parsing git status -s

These are run using one git command per line. Will provide an image if needed as well.

On Bash for Windows terminal.

  • It's not clear what you are trying to do. Do you type these commands directly on the command-line or run a script? Can you provide the code from that script? It's going to be difficult to speed anything up more than git does natively, unless your process is causing issues by opening up separate terminals for each command, or something like that. – LightCC Aug 05 '20 at 20:31
  • Sorry, added a specification, and found an answer to my own question (will add now) – Barrett Ruth Aug 05 '20 at 21:49

1 Answers1

1

The answer to my own extremely specific question:

In my case, I'm trying to parse git status -s in function foo, and call function bar which detects if untracked files exist. The thing is, bar's output is appended to PS1 before foo's. It seems fine, but I'm trying to minimize the amount of git commands called every time in my bashrc. So, insteading of parsing git status -s in foo and then separately finding if untracked files exist in bar, I can call foo, create a untracked_files_exist variable, and make it true if such is given by git status -s. Then I can call bar after, use this untracked_files_exist how I want, and separately append the functions' outputs to PS1 in whichever order after both are called.

if that doesn't make sense: If you want a fast prompt, call a parse-able git function that displays as much information as possible. If you want the prompt to contain such information in a different order than the git command outputs, don't append to PS1 INSIDE of the parsing functions. Do so AFTER so you have control over the order of the prompt.