Last active
August 29, 2015 14:09
-
-
Save willbeaufoy/70412ca6b6bc8070255e to your computer and use it in GitHub Desktop.
Format a file so that no line can exceed 72 characters (for git commit messages)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Outputs to shell. Could be updated to change file in place. Explanation here: | |
# https://stackoverflow.com/questions/26991777/regex-sed-how-to-match-the-last-space-character-in-a-line-before-a-72-charac?answertab=active#tab-top | |
sed 'y/ /³/ | |
s/.*/\ | |
&³/ | |
:space | |
s/\(.*\n\)\([^³]\{0,72\}\)³/\1\2 / | |
t space | |
s/\(.*\) \([^³]*³\)/\1\ | |
\2/ | |
t space | |
s/.\(.*\)./\1/ | |
' file.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment