forked from fl4p/batmon-ha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmt
executable file
·29 lines (24 loc) · 1.02 KB
/
fmt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# See: https://stackoverflow.com/questions/59895/how-to-get-the-source-directory-of-a-bash-script-from-within-the-script-itself
# Note: you can't refactor this out: its at the top of every script so the scripts can find their includes.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
cd "${SCRIPT_DIR}" || exit 1 # This is an unlikely failure, so don't worry too much.
source include.sh
source activate
result=0
parse_filelist "$@"
# Format all by default.
if [ -z "$1" ]; then
black "." || result=1
isort "." || result=1
else
black "${py_files[@]}" || result=1
isort "${py_files[@]}" || result=1
fi
exit $result