How to use pjcolor in a more proper way

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.

  1. 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.
  2. In your .zshrc fille add also a line autoload -Uz pj
  3. In your .zshrc file put also alias pijul="pj"
  4. 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
}

  1. Source your .zshrc file source ~/.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.