2

I have a VPS with CentOS system. The system has a high loadavg in normal time.

I have a Git directory which is very large (nearly 800 MB). When I type command cd to the directory, it takes so long time of the shell to respond.

What happen when I type cd to the Git directory? What can I do to optimize the enter time?

Add my Bash profile here:

This is my .bash_profile file:

function parse_git_dirty {
    [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}

function parse_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\u@\h:\w\[\e[1;36m\]$(parse_git_branch)\[\e[0m\]$ '
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
FisherMartyn
  • 826
  • 1
  • 8
  • 17
  • Probably the *best* thing you can do is refactor your projects so no single directory is 800MB! But no, I can't think of any reason a "cd" should ever be "expensive". Either in "git", and/or a shell. – paulsm4 Nov 04 '15 at 03:57
  • 3
    A plain `cd` wouldn't even look at the contents of the directory. You must have an alias, or a fancy prompt or something doing extra work. –  Nov 04 '15 at 03:59

1 Answers1

4

Check if you have a git PS1 prompt which might take too much time to display (since a git status in a large repo can be costly)

See this gist for instance, which helps disabling the prompt when you do a Ctrl+C:

(extract)

    local this_git_status=""
    if [ -z "${_skip_git_ps1}" ]; then
        this_git_status=$(__git_ps1 "(%s)")
        case $? in
            0 ) : ;;
            130 ) git_ps1_disable;; # If we break that last command because it's too slow, stop trying it
        esac
    fi
    export PS1=": \u@\h \w${this_git_status}; "
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Also check `$PROMPT_COMMAND` – Keith Thompson Nov 04 '15 at 05:44
  • Many thanks. I do find a PS1 promot in my bash dot file. Seems like there are some cache like things, when I get in the directory again even with the origin dot file, the response time is short. I will remove it and test it later. – FisherMartyn Nov 04 '15 at 10:59