Last Updated: June 24, 2016
·
249
· ryrych

Trimming standard output with tr command

Suppose that you want to display the number of commits your local branch is behind the remote branch. Like this:

git le head --not origin/$(git_current_branch) | wc -l
  9

The problem is that the number is preceded with some white space. In order to fix that trim it with wc -d ' ':

git le head --not origin/$(git_current_branch) | wc -l | tr -d ' '
9

You can even turn the command into alias ghb (git head behind for short).

alias ghb="git le head --not origin/$(git_current_branch) | wc -l | tr -d ' '"