Zobrazenie aktualnej branche v terminaly

Thomas

Zobrazenie aktualnej branche v terminaly
« kdy: 24. 11. 2018, 17:41:30 »
Ahojte, skusam si trosku prisposobit terminal, a rad by som videl v terminaly za menom nazov git branche, na ktorej momentalne som checkoutnuty. Nasiel som tento skript ktory by sa mal pridat do ~/.bashrc

Kód: [Vybrat]
parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

Bohuzial funguje len ked sa prepnem v terminaly na superusera. Viete mi prosim povedat, co by som mal nastavit aby som tu branch videl aj bez superusera? Dakujem


Jenda

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #1 kdy: 24. 11. 2018, 18:07:12 »
Třeba jsi to dal do .bashrc superusera? A jinak echo "$PS1", ukáže, jestli se to nastavilo.

Thomas

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #2 kdy: 24. 11. 2018, 18:32:03 »
Třeba jsi to dal do .bashrc superusera? A jinak echo "$PS1", ukáže, jestli se to nastavilo.

pomohlo dakujem :)

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #3 kdy: 24. 11. 2018, 18:45:24 »
pouzij zsh a oh-my-zsh :-)
Děkuji za možnost editace příspěvku.

Fuki

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #4 kdy: 25. 11. 2018, 13:16:20 »
pouzij zsh a oh-my-zsh :-)

Presne tak, da sa to sice aj v bashi ale je to zbytocna pakaren. Nahod si oh-my-zsh alebo fish a tam to mas rovno v zaklade. Su spatne kompatibilne s bash a dokonca este inteligentnejsie.

https://github.com/robbyrussell/oh-my-zsh
https://fishshell.com



Lol Phirae

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #5 kdy: 25. 11. 2018, 16:29:27 »
Su spatne kompatibilne s bash

To určitě potěší aneb rizika psaní bez diakritiky...  :P Jinak ta kompatibilita rozhodně není 100%.

Jenda

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #6 kdy: 25. 11. 2018, 17:25:17 »
Su spatne kompatibilne s bash

To určitě potěší aneb rizika psaní bez diakritiky...  :P Jinak ta kompatibilita rozhodně není 100%.
Pokud to je opravdu striktně slovensky, tak by ten druhý význam mělo slovo "zle", ne "špatně".

gll

  • ****
  • 429
    • Zobrazit profil
    • E-mail
Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #7 kdy: 25. 11. 2018, 17:55:41 »
pouzij zsh a oh-my-zsh :-)

Presne tak, da sa to sice aj v bashi ale je to zbytocna pakaren. Nahod si oh-my-zsh alebo fish a tam to mas rovno v zaklade. Su spatne kompatibilne s bash a dokonca este inteligentnejsie.

https://github.com/robbyrussell/oh-my-zsh
https://fishshell.com

nebo libovolný shell uvnitř emacsu s git-ps1-mode. Sebelepší shell v hloupém terminálu bude vždy horší.

tiletas

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #8 kdy: 25. 11. 2018, 21:05:27 »

blb


.

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #10 kdy: 26. 11. 2018, 08:32:48 »
Pro Git: A1.4 Appendix A: Git in Other Environments - Git in Bash

Kód: [Vybrat]
. ~/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export PS1='\w$(__git_ps1 " (%s)")\$ '


andrej

Re:Zobrazenie aktualnej branche v terminaly
« Odpověď #11 kdy: 26. 11. 2018, 12:07:09 »
Kód: [Vybrat]
# get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
STAT=`parse_git_dirty`
echo "[${BRANCH}${STAT}]"
else
echo ""
fi
}

# get current status of git repo
function parse_git_dirty {
status=`git status 2>&1 | tee`
dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
bits=''
if [ "${renamed}" == "0" ]; then
bits=">${bits}"
fi
if [ "${ahead}" == "0" ]; then
bits="*${bits}"
fi
if [ "${newfile}" == "0" ]; then
bits="+${bits}"
fi
if [ "${untracked}" == "0" ]; then
bits="?${bits}"
fi
if [ "${deleted}" == "0" ]; then
bits="x${bits}"
fi
if [ "${dirty}" == "0" ]; then
bits="!${bits}"
fi
if [ ! "${bits}" == "" ]; then
echo " ${bits}"
else
echo ""
fi
}

export PS1="[\u@\h \w] \[\e[36m\]\`parse_git_branch 2>/dev/null\`\[\e[m\]\n\[\e[31;1m\]\\$\[\e[m\] "