[CentOS] Autorun ability on cd?
Lorenzo Quatrini
lorenzo.quatrini at gmail.com
Wed Aug 5 14:14:57 UTC 2009
James B. Byrne ha scritto:
> I have a little niggling situation that I would like to resolve
> programmatically. I use Git as my SCM and I have release branches
> which are sometimes patched. I find myself sometimes entering the
> working directory tree forgetting that I was last on a release
> branch and not on the master.
>
> What I would like to do is to have a script run every time that I
> enter a directory, check for .git, and if it finds it then simply do
> a git-branch for me so that which I am on is forcefully pointed out
> to me before I proceed to do something foolish.
>
> All I can come up with from searching wrt cd is details on why one
> cannot change the working directory of a running script and various
> kluges around this. I do not wish to change the pwd of the shell, I
> just want some way of testing for a certain file and running a
> specific command if it is found when I enter a working tree. If this
> requires testing every directory that I cd to then I can live with
> that. If instead one can put a script that runs only when one
> enters certain directories then I can live with that as well.
>
> Is there any way to do this?
>
I did a simple test:
cd /tmp
touch .git
export PROMPT_COMMAND='echo -ne
"\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"; if [ -f .git
] ; then echo WARNING: .git DIRECTORY ; fi '
and now every time I cd on that directory and every time I issue a command (on
that directory) I get the warning.
Of course you can do something more elegant (for example change the color of
the whole prompt...)
Don't know the impact on performance...
hope this helps.
--
Regards
Lorenzo
More information about the CentOS
mailing list