macOS 开发环境配置

macOS 开发环境配置

  • 终端:iTerm2 download
  • 软件安装器:brew
1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Shell:zsh
1
2
3
4
5
6
#查看系统当前使用的shell
echo $SHELL
#查看系统是否安装了zsh
cat /etc/shells
#安装zsh
brew install zsh
  • 管理zsh:oh my zsh
1
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

安装完成以后,默认Shell的~/.bashrc文件默认不再加载了,替代的是~/.zlogin和~/.zshrc。所以如果你在~/.bashrc里配置了某些设置,需要把她们复制到~/.zshrc中。

  • zsh插件:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#安装zplug
brew install zplug

#安装 zsh-autosuggestions
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

#安装 zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

#安装 autojump
brew install autojump
  • zsh配置文件:
1
2
3
4
plugins=(git sudo brew z zsh-autosuggestions autojump zsh-syntax-highlighting)
# ZPlug
export ZPLUG_HOME=/usr/local/opt/zplug
source $ZPLUG_HOME/init.zsh
  • zsh主题Agnoster字体:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#方案1
#下载
https://github.com/powerline/fonts/blob/master/Meslo%20Dotted/Meslo%20LG%20L%20DZ%20Regular%20for%20Powerline.ttf
#macOS下双击加入到字体库
#进入iTerm2设置-Profiles-Text-Font,选择字体 Meslo LG S DZ Regular for Powerline 字号14

#方案2
#安装 nerd font (https://github.com/ryanoasis/nerd-fonts#option-4-homebrew-fonts)
brew tap homebrew/cask-fonts
brew install --cask font-hack-nerd-font
#进入iTerm2设置-Profiles-Text-Font,选择字体 Hack Nerd Font 字号14
  • zsh配置文件.zshrc:
1
2
3
4
5
# 主题Agnoster
ZSH_THEME="agnoster"
# 最后一行增加
# redefine prompt_context for hiding [email protected]hostname
prompt_context () { }
  • 查找文件:fd
1
brew install fd
  • 查找文件内容:ag
1
brew install the_silver_searcher

配置git全局用户

GPG签名准备

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
您可以通过以下方式验证您的密钥是否已创建
gpg --list-secret-keys --keyid-format SHORT
# 输出
/Users/usera/.gnupg/pubring.kbx
------------------------------------
sec   rsa4096/26D68A6C 2020-05-05 [SC]
      445519A39680DC429EE5DAB2820F7A3D26D68A6C
uid         [ 未知 ] zilong (kaba) <[email protected]>
ssb   rsa4096/4E4294B4 2020-05-05 [E]
# 26D68A6C就是新密钥ID

你可以配置 Git 来签署你的提交:

1
2
3
# Replace 26D68A6C with your key ID
git config --global user.signingkey 26D68A6C
# 在执行 `git commit` 或 `git tag` 时附加参数 -s 可以用证书签署

你也可以告诉 Git 自动签署所有的提交:

1
2
git config --global commit.gpgSign true
git config --global tag.gpgSign true
1
2
git config --global user.email "[email protected]"
git config --global user.name "zilong"

安装CocoaPods及配置国内镜像

https://www.jianshu.com/p/dbfdece084d5 https://mirrors.tuna.tsinghua.edu.cn/help/CocoaPods/

CocoaPods是通过ruby的gem包安装的,首先更换gem的镜像为国内镜像,以加速安装。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 确认当前源
gem sources -l
# 输出
# *** CURRENT SOURCES ***
# https://rubygems.org/

# 更换源
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
# 为了验证你的Ruby镜像是并且仅是ruby-china,执行以下命令查看
gem sources -l
#如果是以下结果说明正确,如果有其他的请自行百度解决
# *** CURRENT SOURCES ***
# https://gems.ruby-china.com/

安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Mac OS X 10.11前
# sudo gem install cocoapods
# Mac OS X 10.11后
sudo gem install -n /usr/local/bin cocoapods

# 显示pod环境变量
pod env

# 更新本地仓库
pod repo update

新版的 CocoaPods 不允许用pod repo add直接添加master库了,但是依然可以:

1
2
3
cd ~/.cocoapods/repos 
pod repo remove master
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

最后进入自己的工程,在自己工程的podFile第一行加上:

1
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

开发中项目迁移

mailagent 项目迁移

make vue-dev 时遇到的问题

1
Error: Node Sass does not yet support your current environment: OS X 64-bit with Unsupported runtime

原因:包里[email protected]用到的版本比较老,需要老版本node的支持才行。

解决方法

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 安装node版本管理工具 n
npm install -g n        
# 利用n安装长期支持版本14.15.0
sudo n 14.15.0

手工删除 node_modules
# 重新安装包
npm install
# npm install 执行完后回报出一些需要修复的漏洞
found 837 vulnerabilities (804 low, 12 moderate, 21 high)
  run `npm audit fix` to fix them, or `npm audit` for details
# 执行修复命令
npm audit fix

Alfred plugin 插件

https://github.com/LeEnno/alfred-terminalfinder

https://github.com/lukewaite/alfred-gitlab

https://github.com/codezm/Alfred-codezm-workflows-timestamp-convert

Last updated on 2022-01-05
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy