Created
January 6, 2010 23:43
-
-
Save threebytesfull/270815 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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