Skip to content

Instantly share code, notes, and snippets.

@shello
Created April 26, 2012 02:15
Show Gist options
  • Save shello/2495224 to your computer and use it in GitHub Desktop.
Save shello/2495224 to your computer and use it in GitHub Desktop.
Functions for wrapping text (80 columns default); and a pbpaste/pbcopy shortcut function.
function ncols() { fold -s -w ${1:-80}; }
function pbncols() {
command -v pbpaste >/dev/null 2>&1 && command -v pbcopy >/dev/null
if [[ $? != 0 ]]; then
echo >&2 "pbpaste and pbcopy are required. Aborting."
return 1
fi
pbpaste | ncols $1 | pbcopy
}
@shello
Copy link
Author

shello commented Apr 26, 2012

Tested with bash 3.2.48 and zsh 4.3.17.

Usage:

$ cat longlines
lorem ipsum dolor sit amet consetetur sadipscing elitr sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
$ cat longlines | ncols > shortlines
$ cat shortlines
lorem ipsum dolor sit amet consetetur sadipscing elitr sed diam nonumy eirmod 
tempor invidunt ut labore et dolore magna
$ cat longlines | ncols 50
lorem ipsum dolor sit amet consetetur sadipscing 
elitr sed diam nonumy eirmod tempor invidunt ut 
labore et dolore magna

pbncols, under Mac OS X, will wrap the text in your pasteboard, and put it back there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment