Last active
May 21, 2018 05:46
-
-
Save sugarmo/8645e8c01297eb0aca38574bd6a8141a to your computer and use it in GitHub Desktop.
An useful bash source file for Mac OS X.
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
# 我的命令库 | |
# 编辑命令 | |
sg-cmdedit() { | |
subl ~/Documents/sugarbash.sh | |
} | |
# 重新加载命令 | |
sg-cmdreload() { | |
source ~/Documents/sugarbash.sh | |
} | |
# 启动代理 | |
sg-proxystart() { | |
export HTTP_PROXY="http://127.0.0.1:1087" | |
export HTTPS_PROXY="http://127.0.0.1:1087" | |
export http_proxy="http://127.0.0.1:1087" | |
export https_proxy="http://127.0.0.1:1087" | |
export ALL_PROXY="http://127.0.0.1:1087" | |
} | |
# 关闭代理 | |
sg-proxyend() { | |
export HTTP_PROXY="" | |
export HTTPS_PROXY="" | |
export http_proxy="" | |
export https_proxy="" | |
export ALL_PROXY="" | |
} | |
# 检查代理状态 | |
sg-proxylog() { | |
echo "HTTP_PROXY = $HTTP_PROXY" | |
echo "HTTPS_PROXY = $HTTPS_PROXY" | |
echo "http_proxy = $http_proxy" | |
echo "https_proxy = $https_proxy" | |
echo "ALL_PROXY = $ALL_PROXY" | |
} | |
# 修改agvtool的build版本号 | |
# agvsetv <新的版本号> | |
sg-agvnv() { | |
agvtool next-version -all | |
} | |
# 修改agvtool的build版本号 | |
# agvsetv <新的版本号> | |
sg-agvsetv() { | |
agvtool new-version -all "$1" | |
} | |
# 修改agvtool的市场版本号 | |
# agvsetmv <新的版本号> | |
sg-agvsetmv() { | |
agvtool new-marketing-version "$1" | |
} | |
# 打印指定作者在一段时间内的commit记录 | |
# gitsum <开始时间> <结束时间> <作者名> | |
sg-gitsum() { | |
git log --since="$1" --until="$2" --author="$3" --pretty=oneline --abbrev-commit --no-merges | |
} | |
# 创建一个tag到新的commit点并push到远端 | |
# gitnewtag <tag的名字> [<新的commit点>] | |
sg-gittag() { | |
if [[ -n "$2" ]]; then | |
git tag "$1" "$2" | |
else | |
git tag "$1" | |
fi | |
git push origin --tag | |
} | |
# 把一个tag移到新的commit点并push到远端 | |
# gitmvtag <tag的名字> [<新的commit点>] | |
sg-gitmvtag() { | |
git push origin ":refs/tags/$1" | |
git tag -d "$1" | |
if [[ -n "$2" ]]; then | |
git tag "$1" "$2" | |
else | |
git tag "$1" | |
fi | |
git push origin --tag | |
} | |
sg-gitcontains() { | |
git branch -a --contains "$1" | |
} | |
sg-gitfixconflict() { | |
git diff --name-only | uniq | while read line; do | |
subl "$line" | |
done | |
} | |
# 解析mobileprovision文件 | |
# provisiondc <path_to_mobileprovision> | |
sg-provisiondc() { | |
security cms -D -i "$1" | |
} | |
sg-entitlementsdc() { | |
codesign -d --entitlements :- "$1" | |
} | |
sg-ipaexport() { | |
xcodebuild -exportArchive -archivePath "$1" -exportPath "$2" | |
} | |
sg-dsymsfind() { | |
# to uppercase name | |
dsyms=$(mdfind "com_apple_xcode_dsym_uuids == $(echo "$1" | tr '[:lower:]' '[:upper:]')") | |
if [[ -z $dsyms ]]; then | |
echo "dsyms not find." | |
else | |
numberofline=$(echo "$dsyms" | wc -l) | |
if (( $numberofline > 1 )); then | |
echo "$dsyms" | |
else | |
filename=$(basename "$dsyms") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
if [[ "$extension" == "xcarchive" ]]; then | |
open -R "$dsyms/dSYMs" | |
else | |
open -R "$dsyms" | |
fi | |
fi | |
fi | |
} | |
# source https://gist.github.com/cjus/1047794 | |
sg-jsonval() { | |
temp=`echo $1 | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $2` | |
echo ${temp##*|} | |
} | |
# 解析crashlog文件 | |
# crashlog <crash_log> [<dSYM_file>] | |
sg-crashlog() { | |
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer | |
SYMBOLICATE_CRASH=$(find /Applications/Xcode.app/Contents/SharedFrameworks/ -name symbolicatecrash) | |
if [[ -z $SYMBOLICATE_CRASH ]]; then | |
echo "symbolicatecrash binary not found." | |
else | |
echo "symbolicatecrash is $SYMBOLICATE_CRASH." | |
if [ -f "$1" ]; then | |
if [[ -n "$2" ]]; then | |
dsyms=$2 | |
else | |
CRASH_JSON=$(head -n 1 "$1") | |
UUID=$(sg-jsonval "$CRASH_JSON" "slice_uuid") | |
if [[ -n "$UUID" ]]; then | |
echo "Required dSYMs UUID is $UUID." | |
# only use first one | |
dsyms=$(mdfind "com_apple_xcode_dsym_uuids == $(echo "$UUID" | tr '[:lower:]' '[:upper:]')" | sed -n 1p) | |
echo "Using dSYMs $dsyms." | |
else | |
dsyms="" | |
echo "WARNING: Value for \"slice_uuid\" key is missing." | |
fi | |
fi | |
if [[ -z $dsyms ]]; then | |
echo "WARNING: dSYMs not specified or not found, but still try to symbolicatecrash." | |
$SYMBOLICATE_CRASH "$1" > "$1_symbolicated.txt" | |
else | |
$SYMBOLICATE_CRASH "$1" "$dsyms" > "$1_symbolicated.txt" | |
fi | |
else | |
echo "$1 file not exists or is not a file." | |
fi | |
fi | |
} | |
# 查看可执行文件的字符 | |
sg-exestr() { | |
if [[ -n "$2" ]]; then | |
strings - -a -arch arm64 $1 | grep $2 | |
else | |
strings - -a -arch arm64 $1 | |
fi | |
} | |
# 查看可执行文件的类 | |
sg-execlass() { | |
if [[ -n "$2" ]]; then | |
otool -ov $1 | grep $2 | |
else | |
otool -ov | |
fi | |
} | |
# 打包 dSYMs 文件 | |
sg-dszip() { | |
zip dSYMs.zip -r ./dSYMs | |
} | |
# 列出当前文件夹的字体的 postscript 名字 | |
sg-logfont() { | |
for file in "$arg"*.{ttf,otf}; do fc-scan --format "%{postscriptname}\n" $file; done | |
} | |
# 用 you-get 下载视频 | |
sg-youget() { | |
you-get -o ~/Movies/you-get/ "$1" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
source path/to/sugarbash.sh
Add this line to your
~/.bash_profile
, it will be load evertime you launch Terminal.