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
.zshrc
file add
fpath=( ~/.zfunc "${fpath[@]}" )
somewhere at the top of the file.
.zfunc
will be the directory to put our new shell script. So do create it. - In your
.zshrc
fille add also a lineautoload -Uz pj
- In your
.zshrc
file put alsoalias pijul="pj"
- Put this code in
pj
file, inside your.zfunc
directory.
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
.zshrc
filesource ~/.zshrc
You 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.