Created
December 5, 2013 19:46
-
-
Save ziz/7812576 to your computer and use it in GitHub Desktop.
TextMate 2 bundle command to strip trailing whitespace from (only) modified lines on save. Released under the MIT license <http://opensource.org/licenses/MIT> - caveat hacker.
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>command</key> | |
<string>#!/usr/bin/env bash | |
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh" | |
if [[ ! -e "$TM_FILEPATH" ]]; then | |
sed -E 's/[[:space:]]*$//' | |
exit | |
fi | |
TMPFILE=$(mktemp /tmp/stwdiff.XXXXXX) | |
if [ $? -ne 0 ]; then | |
cat | |
exit | |
fi | |
SEDCOMMANDS=$(mktemp /tmp/stwdiff.XXXXXX) | |
if [ $? -ne 0 ]; then | |
rm -f "$TMPFILE" | |
cat | |
exit | |
fi | |
cat > "$TMPFILE" | |
diff \ | |
--old-line-format='' \ | |
--new-line-format='' \ | |
--old-group-format='' \ | |
--new-group-format='' \ | |
--unchanged-group-format='' \ | |
--changed-group-format='%dF,%dLs/[[:space:]]*$// | |
' \ | |
"$TM_FILEPATH" "$TMPFILE" > "$SEDCOMMANDS" | |
if [ $? -eq 1 ]; then | |
sed -E -f "$SEDCOMMANDS" "$TMPFILE" | |
else | |
cat "$TMPFILE" | |
fi | |
rm -f "$TMPFILE" "$SEDCOMMANDS"</string> | |
<key>input</key> | |
<string>document</string> | |
<key>name</key> | |
<string>Strip Trailing Whitespace (Modified Lines) on Save</string> | |
<key>outputCaret</key> | |
<string>interpolateByLine</string> | |
<key>outputLocation</key> | |
<string>replaceDocument</string> | |
<key>scope</key> | |
<string>source</string> | |
<key>semanticClass</key> | |
<string>callback.document.will-save</string> | |
<key>uuid</key> | |
<string>3A6AB59D-1CA1-4CED-B1E4-B68A464BFA6E</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment