$ MacOS开发环境最佳实践

$ 系统实用工具

在Finder路径/System/Library/CoreServices/Applications下藏着一堆系统工具:

image-20191223174406801

$ 安装Homebrew

下载安装脚本:

curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh > install.sh

替换中科大镜像源:

BREW_REPO = "git://mirrors.ustc.edu.cn/brew.git"

执行安装脚本:

sh ./install.sh

替换homebrew源为中科大镜像源:

cd "$(brew --repo)"
git remote set-url origin git://mirrors.ustc.edu.cn/brew.git

设置 bintray镜像:

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile

修改homebrew-core源为中科大镜像源:

/usr/local/Homebrew/Library/Homebrew/brew.sh 
HOMEBREW_CORE_DEFAULT_GIT_REMOTE="https://github.com/Homebrew/homebrew-core"

更新:

brew update

参考:Homebrew Core 源使用帮助 (opens new window)

$ 安装GNU命令

brew install coreutils
brew install binutils
brew install diffutils
brew install ed
brew install findutils
brew install gawk
brew install gnu-indent
brew install gnu-sed
brew install gnu-tar
brew install gnu-which
brew install gnutls
brew install grep
brew install gzip
brew install screen
brew install watch
brew install wdiff
brew install wget

默认安装的GNU的命令都会加个“g”的前缀,比如 sed会变成gsed。 之前版本的brew的install命令中可能会有--with-default-names选项 ,可以直接替换默认的命令名。新版本的brew去掉了这个选项,在安装完成后会提示以配置环境变量的方式替换默认命令名。

添加以下环境变量替换默认命令名:

export PATH="/usr/local/opt/binutils/bin:$PATH"
export PATH="/usr/local/opt/ed/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"
export PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/gnu-which/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/gnu-indent/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH"
export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

参考:Install and Use GNU Command Line Tools on macOS/OS X (opens new window)

$ 为脚本创建App入口

方式一:

mkdir -p ${name}.app/Contents/MacOS/${name}
chmod 755 ${name}.app/Contents/MacOS/${name}

方式二(未生效):

修改${name}.app/Contents/Info.plist

<dict>
    <key>CFBundleExecutable</key>
    <string>MyScript</string>
</dict>

参考:Converting a Shell Script Into a *.app File (opens new window)

$ 配置

$ 开启F1 - F12功能键

关于 -> 系统偏好设置 -> 键盘:

keyboard

$ 交换Fn键和Ctrl键

安装Karabiner-Elements (opens new window)并配置如下:

fn
更新时间: 3/14/2022, 12:30:04 PM