Skip to content

Instantly share code, notes, and snippets.

@threebytesfull
Created January 6, 2010 23:43
Show Gist options
  • Save threebytesfull/270815 to your computer and use it in GitHub Desktop.
Save threebytesfull/270815 to your computer and use it in GitHub Desktop.
# add to .bash_profile or whatever
# convenience function to determine location - uses domain from resolv.conf instead
# of network location (which may not always be set correctly)
function currentloc {
local location
local domain=$(cat /etc/resolv.conf | awk '/^domain/ { print $2 }')
case $domain in
*.mycompany.com)
location=work
;;
*)
location=default
;;
esac
echo $location
}
# example command overridden to be location-specific
# e.g. if /usr/bin/somecommand takes an option '-f' to specify an alternative
# config file, this function will replace it to automatically specify the correct
# config file for this location, passing through all supplied command line args
# so for the locations defined above you'd have two config files:
# ~/.somecommand/work/somecommand.conf
# ~/.somecommand/default/somecommand.conf
function somecommand {
command somecommand -f ~/.somecommand/$(currentloc)/somecommand.conf $@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment