You are not logged in.

#1 2009-02-06 05:04:50

Basu
Member
From: Cornell University
Registered: 2006-12-15
Posts: 296
Website

Run command when entering directory

I have all my files in two Git repositories: one for code and the other for personal documents. However I often forget to check which branch I'm on and so end up not commiting very cleanly. Is there some way I can have a 'git branch' run whenever I cd into my repository directories? (the top levels at least)


The Bytebaker -- Computer science is not a science and it's not about computers
Check out my open source software at Github

Offline

#2 2009-02-06 14:46:27

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Run command when entering directory

Probably the most pragmatic solution to that question would be to have cd be an alias to a script you write that calls cd and then does the appropriate action depending on the value of pwd.

In addition, you might want to rethink how you're using git. Basically, I find that the more often I run git status the better. :-D

Finally, if you have a messy commit, you can use various combinations of git rebase, git cherry-pick, git reflog, git reset (hard, soft and mixed can all be useful) and git revert to get yourself back to a more sane situation. Make sure to study those man pages.

Dusty

Offline

#3 2009-02-06 19:11:14

briest
Member
From: Katowice, PL
Registered: 2006-05-04
Posts: 468

Re: Run command when entering directory

I'd rather use shell function, 'cd' may be hard to implement as a shell script. Besides, there is one more possibility (in bash; don't know about other shells) -- PROMPT_COMMAND environment variable; something like:

[briest@kreml ~]$ cdfun() { if [ "$DUPA" != "$PWD" ] ; then  echo "You have entered $PWD"; DUPA="$PWD"; fi; }
[briest@kreml ~]$ export PROMPT_COMMAND=cdfun

Last edited by briest (2009-02-06 19:11:44)

Offline

#4 2009-02-07 12:13:34

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Run command when entering directory

Dusty wrote:

In addition, you might want to rethink how you're using git. Basically, I find that the more often I run git status the better. :-D

+1 smile


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

Board footer

Powered by FluxBB