Skip to content

Instantly share code, notes, and snippets.

@FradSer
Last active Mar 6, 2016
Embed
What would you like to do?
# 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

Loading

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