Make shfmt happier

This commit is contained in:
Michael Wolf
2023-09-30 14:55:00 -06:00
parent 952c7eeb90
commit 7322fc5f71

View File

@@ -1,12 +1,12 @@
function get_os() { function get_os() {
un=$(uname) un=$(uname)
if [[ "$un" = "Linux" ]] ; then if [[ "$un" = "Linux" ]]; then
echo -n "linux" echo -n "linux"
return 0 return 0
fi fi
if [[ "$un" = "Darwin" ]] ; then if [[ "$un" = "Darwin" ]]; then
echo -n "osx" echo -n "osx"
return 0 return 0
fi fi
@@ -16,16 +16,16 @@ OPERATING_SYSTEM=$(get_os)
# For a given file, return its corresponding project root. # For a given file, return its corresponding project root.
function project_root() { function project_root() {
pushd $(dirname "$1") 2>&1 > /dev/null pushd $(dirname "$1") 2>&1 >/dev/null
out=$(git rev-parse --show-toplevel) out=$(git rev-parse --show-toplevel)
ret="$?" ret="$?"
popd 2>&1 > /dev/null popd 2>&1 >/dev/null
if [[ "$ret" != "0" ]] ; then if [[ "$ret" != "0" ]]; then
echo -n "" echo -n ""
return 1 return 1
fi fi
echo -n "$out" echo -n "$out"
return 0 return 0
} }
@@ -59,11 +59,11 @@ function normalize_dir_of_file() {
} }
function resolve_symlink() { function resolve_symlink() {
if [[ "$OPERATING_SYSTEM" = "osx" ]] ; then if [[ "$OPERATING_SYSTEM" = "osx" ]]; then
out=$(readlink "$1") out=$(readlink "$1")
else else
out=$(readlink -f "$1") out=$(readlink -f "$1")
fi fi
echo "$out" echo "$out"
} }
@@ -73,18 +73,21 @@ function custom_formatter() {
file_type="$2" file_type="$2"
maybe="$root/.would-reformat/$file_type" maybe="$root/.would-reformat/$file_type"
if [[ -f "$maybe" ]] ; then if [[ -f "$maybe" ]]; then
echo "$maybe" echo "$maybe"
return return
fi fi
echo "use-default" echo "use-default"
} }
## WOULD_FORMAT_PROJECT_ROOT=$(project_root $1)
# FIXME: This needs to be made customizable # FIXME: This needs to be made customizable
function sniff_file_type() { function sniff_file_type() {
ff=$1 ff=$1
shift shift
file_type= file_type=
if [[ $ff == *.py ]]; then if [[ $ff == *.py ]]; then
@@ -105,22 +108,25 @@ function sniff_file_type() {
file_type="jsx" file_type="jsx"
elif [[ $ff == *.tsx ]]; then elif [[ $ff == *.tsx ]]; then
file_type="tsx" file_type="tsx"
elif [[ $ff == *.css ]] ; then elif [[ $ff == *.css ]]; then
file_type="css" file_type="css"
elif [[ $ff == *.scss ]] ; then elif [[ $ff == *.scss ]]; then
file_type="scss" file_type="scss"
elif [[ $ff = *.sh ]]; then elif [[ $ff = *.sh ]]; then
file_type="sh" file_type="sh"
elif [[ $ff = *.go ]] ; then elif [[ $ff = *.go ]]; then
file_type="golang" file_type="golang"
elif [[ $ff = *.dart ]] ; then elif [[ $ff = *.dart ]]; then
file_type="dart" file_type="dart"
fi fi
echo $file_type echo $file_type
} }
function wrflog() { function wrflog() {
echo "$@" >> /tmp/wrflog echo "$@" >>/tmp/wrflog
} }
# WOULD_FORMAT_INSTALLATION_ROOT=$(wfroot)
export WOULD_FORMAT_PROJECT_ROOT