Boris Grunwald
Boris Grunwald

Reputation: 2722

Small delay when executing MacOS terminal commands

I've noticed that there is a small but noticeable delay when I execute simple commands like ls and cd in the terminal. Can anyone tell me how to go about troubleshooting this problem? I really don't know where to start.

Upvotes: 0

Views: 2114

Answers (1)

Socowi
Socowi

Reputation: 27340

Summary of the discussion in the comments:

At each prompt you are executing the command __git_ps1 which creates a small delay. The time needed to execute __git_ps1 depends on your git configuration and your current working directory.

To get a faster prompt you could

  • improve the script __git_ps1 to run faster (probably not a real option).
  • use a simple prompt that does not show all the information given by __git_ps1.
  • use a timeout such that __git_ps1 is used only if it's not too slow (see following section).
  • run __git_ps1 only when something changes (not explained here since you would have to identify all commands that could change the output of __git_ps1).

Use a timeout

In bash the command timeout n cmd executes cmd for at most n seconds. When used in your prompt

PS1="[\\u@\\h \\W\$(__git_ps1 \" (%s)\")]\\\$ "

becomes

PS1="[\\u@\\h \\W\$(timeout 0.2 __git_ps1 \" (%s)\")]\\\$ "

You can adjust the timeout to your needs.

Upvotes: 1

Related Questions