OK, I can already hear you saying “here we go again”. Well, I’m sorry that I’m not really in the mood to report much on my personal life (though, rest assured, everything is really going smooth, so don’t worry). Maybe this blog will undergo certain changes in the near future, but right now I’m not at liberty to discuss this (just wait a few more weeks).

For today I’ve got two small tips for you. The first is about printing directly from mutt (not that I print mails that often). If you’re not satisfied with the default output you can use a2ps (which has many other uses as well!) to produce a more readable output. To do that simply place this into your .muttrc:set print_command="a2ps -r --columns=2 -j -B|lpr" This of course assumes that you can use lpr to print on your system (which is my preferred way of printing stuff).

git/zsh dirty work treeThe next tip builds on my previous post about a zsh prompt showing the current branch if inside a git repo. Instead of just showing the branch-name we want to indicate whether the working directory is clean or if it has uncommitted changes. With git there are two kinds of “dirty” though: changes in the index but not committed and changes not in the index. So we have two indicators, which makes the whole thing look like the image. Red is changes not in index, and green is changes already added to the index. The code you’re gonna need in your .zshrc looks like this:

# Set a nice git-prompt (calls git_status())
git_prompt_info() {
  local git_dir ref br;
  git_dir=$(git rev-parse --git-dir 2> /dev/null) || return
  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  branch_prompt=${ref#refs/heads/}
  if [ -n "$branch_prompt" ]; then
    status_icon=$(git_status)
    echo "$status_icon%{$fg[yellow]%} [$branch_prompt]"
  fi
}
# Show character if index and/or work-tree are dirty
git_status() {
  my_status=$(git status)

  if [[ "$my_status" == *"Changes to be committed"* ]]; then
    output="%{$fg[green]%}+"
  fi
  
  if [[ "$my_status" == *"Changed but not updated"* ]]; then
    output="$output%{$fg[red]%}*"
  fi

  echo $output
}

Now all you’ve gotta do is call $(git_prompt_info) somewhere in your RPS1.