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