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

Addeds sourceable system function library

  • Loading branch information...
kopischke committed Apr 9, 2013
1 parent 1627d91 commit 22697ca695380d23bf759836c0024430bfc51298
Showing with 14 additions and 0 deletions.
  1. +14 −0 src/lib/system.sh
View
@@ -0,0 +1,14 @@
+function get_global_locale {
+ defaults read .GlobalPreferences AppleLocale 2>/dev/null
+}
+
+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"
+}

0 comments on commit 22697ca

Please sign in to comment.