This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Default to fetching global locale

If all else fails, take the long route.
  • Loading branch information...
kopischke committed Apr 9, 2013
1 parent eee25f7 commit 93a0110a9fccca08aae3bc991c03ffdfbcadfd5b
Showing with 7 additions and 7 deletions.
  1. +7 −7 src/lib/system.sh
View
@@ -4,11 +4,11 @@ function get_global_locale {
function get_locale {
local locale
- # get cached value if requested and present
- [[ $1 == '--cached' && -f "$2" ]] && locale=$(while read -r; do echo "$REPLY"; break; done < "$2")
- # get the defaults value if there is no cached value present, or if none has been requested
- [[ -z "$locale" ]] && locale=$(get_global_locale)
- # asynchronously refresh cache (if requested)
- [[ $1 == '--cached' ]] && { { mkdir -p "${2%/*}"; get_global_locale > "$2"; } & disown; }
- echo "$locale"
+ # get cached value if requested and present, refresh asynchronously
+ if [[ $1 == '--cached' ]]; then
+ [[ -f "$2" ]] && locale=$(while read -r; do echo "$REPLY"; break; done < "$2")
+ { { mkdir -p "${2%/*}"; get_global_locale > "$2"; } & disown; } 2>/dev/null
+ fi
+ # get the defaults value otherwise
+ [[ -n "$locale" ]] && echo "$locale" || get_global_locale
}

0 comments on commit 93a0110

Please sign in to comment.