It took me more than an hour to do this right. At first it seems like a simple problem. But the naive solutions didn’t quite work out. So I’m sharing the way, how to use pjcolor in transparent way for zsh. The method is for zsh, but I think any shell can achieve the same thing.
- edit your
.zshrcfile add
fpath=( ~/.zfunc "${fpath[@]}" )somewhere at the top of the file.
.zfuncwill be the directory to put our new shell script. So do create it. - In your
.zshrcfille add also a lineautoload -Uz pj - In your
.zshrcfile put alsoalias pijul="pj" - Put this code in
pjfile, inside your.zfuncdirectory.
pj() {
case "$1" in
change)
if [ "$2" = "" ]; then
pijul change | pjcolor
else
shift
pijul change "$@" | pjcolor
fi
;;
diff)
if [ "$2" = "" ]; then
pijul diff | pjcolor
else
shift
pijul diff "$@" | pjcolor
fi
;;
*)
pijul "$@"
;;
esac
}
- Source your
.zshrcfilesource ~/.zshrcYou may need to invoke another instance of your terminal to changes take effects.
Now you should have pijul command that colors the output by default, as a bonus you also get pj alias that do the same thing. Script should respect all the additional flags and options. Just keep in mind to keep pjcolor in your $PATH
I think its good place to share it. I will also add this the README.md file in my repository.