Miljenko Baković
Miljenko Baković

Reputation: 21

Display current branch name in a console (tcsh)

I'm using tcsh at work (unfortunately, I can't change that fact) and I'm going crazy because I'm not able to make console display current branch name when I'm in git repo.

I found this a while ago:

http://articles.bvsatyaram.com/2010/09/display-git-branch-name-in-console.html

and that's working just perfect in bash, but I didn't manage to make it work in tcsh since it's not that similar.

I would appreciate any type of help.

Upvotes: 2

Views: 5325

Answers (3)

digitalguy99
digitalguy99

Reputation: 549

You can try:

alias __git_current_branch 'git rev-parse --abbrev-ref HEAD >& /dev/null && echo "{`git rev-parse --abbrev-ref HEAD`}"'
alias precmd 'set prompt="%n@%m[%c2]`__git_current_branch` "'

source: https://thrysoee.dk/gittcsh/

Upvotes: 1

Xiaoliang Wu
Xiaoliang Wu

Reputation: 1

alias GIT_BRANCH_CMD "sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/\(\1)/'"
alias cd 'chdir \!*;set prompt="%B%n%b@%B%m: %~/%{\033[32;40m%}"`GIT_BRANCH_CMD`"%{\033[0m%}>"'
alias co 'eval "git checkout \!*;cd .;"'

now, use co to checkout branch , it will auto refresh the branch name

Upvotes: 0

thameera
thameera

Reputation: 9473

I gave the following not-so-perfect solution to one of my friends who was stuck in csh, I think it'd work in tcsh as well. It's just an edit of the bash version.

alias GIT_BRANCH_CMD "sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/\(\1)/'"
alias cd 'chdir \!*;set prompt="%{\033[32;40m%}"`whoami`@`hostname`": %{\033[33;40m%}%~%{\033[37;40m%}"`GIT_BRANCH_CMD`"%{\033[32;40m%} >%{\033[0m%} "'
cd ~

Add this to the .cshrc and when you move to a new directory it will show the branch within parentheses. I think this won't work when you change the branch while you're in the directory. As I remember he used some other workaround for that, something like aliasing the dot (.) to change the directory down the tree and up, so it will refresh the branch.

Upvotes: 1

Related Questions