====== GIT informatie op de prompt ====== Vooral als je met veel branches werkt is het soms lastig bij te houden in welke branch je je bevind en of je al een commit hebt uitgevoerd. Met deze instellingen krijg je die in formatie in je prompt titel. ''vi .bashrc'' en voeg toe: # User specific aliases and functions # Git info on prompt function _git_prompt() { local git_status="`git status -unormal 2>&1`" if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then if [[ "$git_status" =~ nothing\ to\ commit ]]; then local ansi=42 elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then local ansi=43 else local ansi=41 fi if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then branch=${BASH_REMATCH[1]} test "$branch" != master || branch='master' else # Detached HEAD. (branch=HEAD is a faster alternative.) branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null || echo HEAD`)" fi echo -n '\[\e[0;37;'"$ansi"';1m\]'"$branch"'\[\e[0m\] ' fi } function _prompt_command() { PS1_SET_TITLE='\[\e]0;\u@\h:\w\a\]' PS1="${PS1_SET_TITLE}""`_git_prompt`"'\u@\h:\[\e[1;32m\]\w>\[\e[0m\] ' } PROMPT_COMMAND=_prompt_command log uit en in. De prompt ziet er daarna zo uit. Maak een directory aan voor je locale gitrepositories en clone een git repo user@workstation:~> mkdir gitrepos user@workstation:~> cd gitrepos/ user@workstation:~/gitrepos> user@workstation:~/gitrepos> git clone git://host.org/project.git Vervolgens zal je zien dat je prompt veranderd als je naar de repository directory gaat: user@workstation:~/gitrepos> ls project user@workstation:~/gitrepos> cd project/ master user@workstation:~/gitrepos/project> Als je nu? een branch aanmaakt en daar op over gaat gaat je prompt direct mee: master user@workstation:~/gitrepos/project> git checkout -b develop Switched to a new branch 'develop' develop user@workstation:~/gitrepos/project>