Skip to content

Instantly share code, notes, and snippets.

@ioggstream
Last active April 20, 2016 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioggstream/ab1c71f7ec358bbf9c66 to your computer and use it in GitHub Desktop.
Save ioggstream/ab1c71f7ec358bbf9c66 to your computer and use it in GitHub Desktop.
Switch git url between https and ssh via networkmanager
#!/bin/bash
export LANG=C
progname=$0
interface=$1
status=$2
case "$status" in
up|down|vpn-up|vpn-down)
# You may need to wait a bit before the interface is up before
# all the proper checks returns true, eg routes, ...
sleep 10
# Replace the following check with whatever you need.
/bin/nmcli device show wlan0 | grep -q 'GENERAL.CONNECTION:\s+CorporateLan'
is_corporate=$?
logger -t NetworkManager "Using $progname dispatcher to set git config while running $interface $status. is_corporate: $is_corporate "
if [ $is_corporate != 0 ]; then
git config --global url."https://example.com/".insteadOf git@example.com:
else
git config --global --unset url.https://example.com/.insteadof
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment