Quick Copy For The Current Directory Path

Copying the current command line directory path is a frequent task. On a Mac, this can be sped up using `pbcopy`. A little command Apple included that takes whatever it's fed and copies it to the clipboard^1^^. The basic command string to grab the current directory path with it is:

pwd | pbcopy

Unfortunately, `pwd` sends a newline to `pbcopy` which is dutifully included on the clipboard. Rarely useful. Often annoying. The `tr` command comes to the rescue by removing the newline:

pwd | tr -d '\n' | pbcopy

That makes a nice little command string, but too long to be useful. The last step is to add an a alias to `~/.bash_profile` so it can be called with only a few keystrokes.

alias pwc="pwd | tr -d '\n' | pbcopy"

The old standard `pwd` prints the current directory path, as always, and the newly created `pwc` makes a copy of it that's ready to paste.


1. Officially, Apple calls it the Pasteboard, but everyone I know, including myself, calls it the clipboard. So, I'm sticking with that.