Created
June 5, 2023 23:32
-
-
Save dereckson/80a746b408c0cf0b688a09db31d5c881 to your computer and use it in GitHub Desktop.
Allow to reindent a file, inline
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
#!/bin/sh | |
# ------------------------------------------------------------- | |
# Reindent a file from x to y spaces | |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
# Project: Nasqueron | |
# License: BSD-2-Clause | |
# Example: reindent 2 4 HelloWorld.vue | |
# ------------------------------------------------------------- | |
set -e | |
# ------------------------------------------------------------- | |
# Parse arguments | |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
if [ $# -lt 3 ]; then | |
echo "Usage: $(basename $0) <current> <expected> <file>" >&2 | |
exit 1 | |
fi | |
CURRENT_SPACES=$1 | |
EXPECTED_SPACES=$2 | |
FILENAME=$3 | |
# ------------------------------------------------------------- | |
# Reindent | |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | |
TMP_FILE=$(mktemp -t reindent) | |
unexpand -t $CURRENT_SPACES $FILENAME > $TMP_FILE | |
expand -t $EXPECTED_SPACES $TMP_FILE > $FILENAME | |
rm $TMP_FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment