Large .bash_profile increasing time for terminal to do things. Able to fix?
If you type set -x
into the terminal, it will print every command it executes from that point on, so to find the culprit, type set -x
and hit return, then - paying attention to the lines scrolling by on the screen - watch for whatever command takes a long time to run.
The number of +
characters at the beginning of each line tell you how deeply nested the command is. If you scroll up a bit, you can find the "parent" command.
The commands you see when you hit return are all triggered by the last line of your bashrc, where you set the contents of the variable PS1
. Every time you hit return, the contents of that variable are executed and the result is shown as the "prompt" (the bit before the cursor, e.g. something like user@box ~ $
).
To get out of this mode, you can type set +x
or just close that terminal window/tab (see What does set -x
do?).
PS: I would hazard a guess that your git status commands are slowing down the prompt. If you install both git
and bash-completion
from Homebrew, you can use __git_ps1
to do this and get rid of all the git related functions from your bashrc. As an example, this is what it looks like on my machine:
if [[ -f /usr/local/etc/bash_completion ]]; then
. /usr/local/etc/bash_completion
fi
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_SHOWUNTRACKEDFILES=1
PS1='\w \$ '
if type __git_ps1 &>/dev/null; then
PS1='\w$(__git_ps1 | sed -e "s/=)$/)/") \$ '
fi