Old but not bus­ted … – Die­ser Inhalt wur­de vor mehr als 9 Jah­ren publi­ziert. Die Kor­rekt­heit und Ver­füg­bar­keit von Links kön­nen lei­der nicht gewähr­leis­tet werden.

Auch wenn ich nicht wirk­lich ‚viel‘ code, aber so ab und zu fällt ja doch mal was an … In den letz­ten Jah­ren v.a. aber eher Klein(st)beiträge zu bereits bestehn­dem Code Ande­rer, statt eige­ner Projekte.

2010 ver­such­te ich mei­ne ers­ten Schritt(ch)e(n) mit Git und such­te dafür eine geeig­ne­te Platt­form. – Nur Kom­man­do­zei­le mit eige­nem Git-Ser­ver war mir damals IMHO zu umständ­lich und wohl auch zu ner­dy. ‚Damals‘ gabs zwar schon Git­hub (und dort hat­te ich auch seit 2009 einen unge­nutz­ten Account), aber als F(L)OSS-Verfächter woll­te ich mehr Com­mu­ni­ty und fand letzt­lich Gito­rious, wo ich mir einen Account zuleg­te. (So jeden­falls mei­ne Erinnerung …)

Bei Gito­rious gab es anfäng­lich kei­nen Issue-Tra­cker und die Inter­ak­ti­on über Web­ober­flä­che war, im Gegen­satz zu Git­hub, sehr beschränkt. So kam es im Lau­fe der fol­gen­den fünf Jah­re zur vor­ran­gi­gen Nut­zung mei­nes Github-Accounts.

Im letz­ten Jahr gab es Bedarf für die Zusam­men­ar­beit meh­rer Per­so­nen ein einem Pro­jekt (etwas bug fixing im Code von POLYKON) – dabei soll­te das erst ein­mal nicht in der Öffent­lich­keit pas­sie­ren. Somit schied Git­hub (auf Grund der Kos­ten) aus und ich fand Bit­Bu­cket und erstell­te auch dort einen Account.

In Sum­me hat­te ich bis dahin also drei Accounts bei unter­schied­li­chen Anbie­tern für Git-Repo­si­to­ries gesammelt …

Git­Lab-Logo

Letz­te Woche woll­te ich mal wie­der bei Gito­rious schau­en, was so los ist und stell­te fest, dass Git­Lab den Laden über­nom­men hat und man emp­fiehlt, die eige­nen Gito­rious-Repos auf Git­Lab umzu­zie­hen. Dann habe ich mich also mal bei Git­Lab umge­schaut und schwupps, war der vier­te Account geklickt … 😉

War­um nun noch einen vier­ten Account?

  • GitLabs Web­in­ter­face ist schnell
  • Git­Lab bie­tet nicht­öf­fent­li­che Repos an
  • Git­Lab bie­tet eig. alle (von mir benutz­ten) Fea­tures wie Git­hub (und ist sogar bes­ser ;))
  • Git­Lab gibts in der Com­mu­ni­ty Ver­si­on kostenlos
  • und jetzt der Knal­ler: per Klick konn­te ich (mit etwas Recher­che) alle Repos aus den ande­ren drei Accounts importieren
  • wenn die But­ze iwann (vllt.) mal zu macht, dann kann ich/man das immer noch sel­ber hosten
  • das Icon ist süüüß … 😉

Zusam­men­ge­fasst: Aktu­ell schrumpfe/konsolidiere ich mei­ne Git-Platt­form-Accounts. Gito­riuous is schon weg und gleich kommt noch der Bit­bu­cket-Account dran. Bei Git­hub wer­de ich dann wohl nur noch wg. der Issue- und Pull-Request-Zwe­cke sein, die eige­nen Pro­jek­te kom­men dort auf jeden Fall weg.

Mal schau­en, ob sich das Auf­räu­men lang­fris­tig als klug erwei­sen wird …

Old but not bus­ted … – Die­ser Inhalt wur­de vor mehr als 13 Jah­ren publi­ziert. Die Kor­rekt­heit und Ver­füg­bar­keit von Links kön­nen lei­der nicht gewähr­leis­tet werden.

The fol­lo­wig post is not writ­ten by mys­elf. It’s a copy! – Today I found the artic­le in the Goog­le Cache and thought the­re are more peo­p­le (than me) inte­res­ted in the archi­ved text that was ori­gi­nal­ly published at a blog named M‑x Kel­sin.

Let’s start …

After rea­ding ano­ther cool blog post about put­ting your cur­rent git branch in your bash prompt I deci­ded I nee­ded to try this out. Once I got it working I added in color coding to see the sta­tus of the cur­rent check­out as well!

First off, you need bash-com­ple­ti­on and git instal­led on your ser­ver (bash-com­ple­ti­on and git-core on Debian/Ubuntu). Once instal­led you can enable bash com­ple­ti­on in the sys­tem wide bash file (/etc/bash.bashrc) or in your own ~/.bashrc by adding the­se lines (Cle­ar­ly if you are not on Debian/Ubuntu dou­ble check file paths):

# Completion
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

Once this is all set you should have a func­tion cal­led git_ps1 available. Try it out by just run­ning git_ps1 on your com­mand line from a git repo. You should get the branch name retur­ned insi­de parenthesis’s.

Now comes my varia­ti­ons on how to include this in your prompt. My enti­re ~/.bash_prompt file can be found on my git repo. I source this file into my ~/.bashrc. The two most inte­res­t­ing parts are the func­tion that deter­mi­nes the color of the branch based on git-sta­tus out­put and the func­tion that gets the branch name. Branch name is pret­ty simp­le. We check that the __git_ps1 func­tion is available and if it is, check that we’­re in a branch using it. If we are we echo the branch name. Pret­ty clean.

prompt_git_branch() {
    if type -p __git_ps1; then
        branch=$(__git_ps1 '%s')
        if [ -n "$branch" ]; then
            echo -e "$branch"
        fi
    fi
}

The next func­tion has to grep stuff out of git sta­tus to deter­mi­ne what sta­te the repo is in. If we are com­ple­te­ly up to date we use green. If I have local chan­ges it’s blue. If we have files in our index rea­dy to be com­mit­ted I use red. This is real­ly gre­at with my home direc­to­ry cau­se it helps remind me to add new dot­files that I don’t care about to .gitigno­re (or com­mit them if they should be public con­fig files).

prompt_git_branch_color() {
    if type -p __git_ps1; then
        branch=$(__git_ps1 '%s')
        if [ -n "$branch" ]; then
            status=$(git status 2> /dev/null)

            if $(echo $status | grep 'added to commit' &> /dev/null); then
                # If we have modified files but no index (blue)
                echo -e "\033[1;34m"
            else
                if $(echo $status | grep 'to be committed' &> /dev/null); then
                    # If we have files in index (red)
                    echo -e "\033[1;31m"
                else
                    # If we are completely clean (green)
                    echo -e "\033[1;32m"
                fi
            fi
        fi
    fi
}

It took some play­ing but I final­ly found the right final line to cor­rect­ly tell bash which cha­rac­ters in the prompt are visi­ble. If anyo­ne has a good way of making the­se func­tions smal­ler or fas­ter I’d love to hear it. I had some trou­ble making sure that the func­tions were always exe­cu­ted (not just on a new shell’s crea­ti­on, but on every dis­play of PS1). The speed is FINE on all of my com­pu­ters but more speed never hurts.