Last active
March 6, 2016 17:37
-
-
Save FradSer/c0483bc175783a7e0717 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Surge for Mac | |
function surge_add() { | |
if [ "$1" == "--proxy" -o "$1" == "-p" -o "$1" == "--direct" -o "$1" == "-d" ]; then | |
if [ "$(cat ~/.surge.conf | grep -c $2)" -eq 0 ]; then | |
if [ "$1" == "--proxy" -o "$1" == "-p" ]; then | |
sed -i '' -e '541i \ | |
DOMAIN-SUFFIX,'$2',Proxy' ~/.surge.conf; | |
fi; | |
if [ "$1" == "--direct" -o "$1" == "-d" ]; then | |
sed -i '' -e '541i \ | |
DOMAIN-SUFFIX,'$2',DIRECT' ~/.surge.conf; | |
fi; | |
osascript -e 'tell application "Surge" to quit'; | |
osascript -e 'run application "/Applications/Surge.app/"'; | |
else | |
echo '"'"$2"'"'' already exists.'; | |
cat ~/.surge.conf | grep $2; | |
fi; | |
else | |
echo "usage: surge_add [--proxy|-p|--direct|-d] [URL]."; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
因为

~/.surge.conf
必须以FINAL,Proxy
结尾,所以会用sed
把配置写在第 541 行,你可以和我一样用# Custom
把第 540 行替换掉。