Skip to content

Instantly share code, notes, and snippets.

@dereckson
Created June 5, 2023 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dereckson/80a746b408c0cf0b688a09db31d5c881 to your computer and use it in GitHub Desktop.
Save dereckson/80a746b408c0cf0b688a09db31d5c881 to your computer and use it in GitHub Desktop.
Allow to reindent a file, inline
#!/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