Skip to content

Instantly share code, notes, and snippets.

@FradSer
Last active March 6, 2016 17:37
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 FradSer/c0483bc175783a7e0717 to your computer and use it in GitHub Desktop.
Save FradSer/c0483bc175783a7e0717 to your computer and use it in GitHub Desktop.
# 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
}
@FradSer
Copy link
Author

FradSer commented Mar 6, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment