123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #!/bin/bash
- [[ "$0" == *'/'* ]] && { cd "${0%/*}" || exit 1; }
- for d in yad grep sed ./get_location_id; do
- type -f $d >/dev/null || exit 1
- done
- locations_file="files/selected_locations"
- conf="files/get_weather.d/conf"
- nl=$'\n'
- result=''
- selloc=() # selected locations
- yadcmd=(yad --center --window-icon weather --title "Weather locations")
- search_and_select() {
- query=''
- while [ -z "$query" ]; do
- fuzzy=''
- query="$("${yadcmd[@]}" --entry-label "Enter location query" --button=Search:0 --button=Fuzzy\ search:222 --button=Cancel:252 --entry)"
- case $? in
- 252) return
- ;;
- 222) fuzzy="-f"
- ;;
- esac
- done
- mapfile -t morloc < <(./get_location_id $fuzzy "$query")
- result="$("${yadcmd[@]}" --entry-label "Add location" --button=OK:0 --button=Cancel:252 --entry "${morloc[@]}")"
- case $? in
- 252) return
- ;;
- esac
- }
- if [ -r "$locations_file" ]; then
- mapfile -t selloc <"$locations_file"
- else
- search_and_select
- fi
- while [ -z "$result" ]; do
- result="$("${yadcmd[@]}" --entry-label "Choose location" --button=OK:0 --button=Add\ more:222 --button=Cancel:252 --entry "${selloc[@]}")"
- case $? in
- 252) exit
- ;;
- 222) search_and_select
- ;;
- esac
- result="${result%"${result##*[![:space:]]}"}"
- selloc=( "$result" "$(for i in "${selloc[@]}"; do [[ "$i" == "$result" ]] && continue; echo "$i"; done)" )
- done
- ere='^[[:space:]]*geoid=[0-9]+'
- [ -r "$conf" ] && grep -qE "$ere" "$conf" && sed -Ei "s/$ere/geoid=${result%% *}/" "$conf" || echo "geoid=${result%% *}" >> "$conf"
- conky -c conkyrc.lua &
- for i in "${selloc[@]}"; do echo "$i"; done > "$locations_file"
|