fixed alias with spaces and printing with aliases

This commit is contained in:
spinach 2023-01-29 19:23:42 -05:00
parent 62a2e6be80
commit b6eba78754

View File

@ -5,7 +5,6 @@
usage() { usage() {
cat <<EOF cat <<EOF
usage: $0 [-c][-p][-f][-s][-h][-r [option]] usage: $0 [-c][-p][-f][-s][-h][-r [option]]
Queries Bluebikes API to get recent bike status Queries Bluebikes API to get recent bike status
Options: Options:
@ -115,11 +114,9 @@ set_station_alias() {
exit 1 exit 1
fi fi
# gojq hates qoutes # adding to file
FMT_ALIAS=$(printf '"%s"' $(echo $ALIAS | tr -d '"')) tmp=$(cat "$ALIASES_FILE" | gojq --arg name "$ALIAS" --arg id "$STATION_ID" 'setpath([$id]; $name)')
FMT_STATIONID=$(printf '"%d"' $STATION_ID) echo "$tmp" > "$ALIASES_FILE"
echo "$(cat "$ALIASES_FILE" | gojq ".$FMT_STATIONID |= $FMT_ALIAS")" > "$ALIASES_FILE"
# printing change # printing change
if [[ -z "$ALIAS" ]] ; then if [[ -z "$ALIAS" ]] ; then
@ -181,7 +178,7 @@ print_status() {
id=$(printf '"%d"' $STATION_ID) id=$(printf '"%d"' $STATION_ID)
ALIAS=$(cat "$ALIASES_FILE" | gojq ".$id" | tr -d '"') ALIAS=$(cat "$ALIASES_FILE" | gojq ".$id" | tr -d '"')
if [[ "$ALIAS" != "null" ]] ; then if [[ "$ALIAS" != "null" && ! -z "$ALIAS" ]] ; then
# if there is an alias # if there is an alias
STATION_NAME="$ALIAS" STATION_NAME="$ALIAS"
fi fi