背景:19 年 5 月某天,新开发的功能刚刚进入联调阶段,正愉快的 debug,忽然 cpu 飙升,电脑咯咯的响,并伴随着发热,而后就很卡,一帧一帧的,我瞄了一眼电量,竟然 10%不到,我在想我是一直插着电源呢,内心想着重启试试吧,而后就开不开机了,每次开机都是亮一下电源图标,就没而后了。而后我就赶忙预定了售后,送了过去,维修人员说,这种状况,返厂,等修好了通知我。 (忍不住吐槽:带bar的新款常常出问题,我好几位同事的都有过问题,并且在vim期间,这个bar摸起来没有一点手感)javascript
... 三天后,收到通知,取电脑,说是主板坏了,已经更换,我想 17 年底买的,还在 2 年保修内,不用花钱贼开心,一开机,就傻眼了,哇全新的,毛都没留,代码还没提交呢,我问了一下,他说新版带 bar 款硬盘、主板、cpu 是连在一块儿的,只能一块儿换,顿时内心有一万只 🦙。。。css
代码不得不从新写了,还好产品给了我时间,不用通宵,不过没想到的是搭建温馨的环境就花了半天时间,遂决定写下这篇文章,并把个人配置文件备份到仓库。html
做为一名开发人员,拿到全新的 mac,首先要作的就是搭建适合本身的开发环境(笔者是前端,本文是偏全栈的配置)了。前端
我的习惯,不少软件是经过 brew 来装的。vue
首先要安装 brew,打开终端,输入:java
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
node
经常使用命令:python
brew ls
:查看当前安装了哪些包brew cask ls
:查看当前安装了哪些应用brew search xxx
:搜索 xxx 包brew install xxx
:安装 xxx 包brew cask install xxx
:安装 xxx 包brew info xxx
:查看 xxx 包的信息【注 ⚠️】: brew
是下载源码,而后解压,而后 ./configure && make install
,同时会包含相关依赖库,并自动配置好环境变量,易于卸载。 brew cask
是下载已经编译好的应用包(.dmg/.pkg),解压后统一放到某一目录下,一样易于卸载且干净react
brew search chrome
brew cask install google-chrome
brew search visual-studio-code
brew cask install visual-studio-code
brew search sublime-text
brew cask install sublime-text
brew search robo3t
brew cask install robo3t
brew search charles
brew cask install charles
brew search docker
brew cask install docker
brew search iterm2
brew cask install iterm2
,将其设置为默认终端:⌃⇧⌘\brew search tmux
brew install tmux
brew search git
brew install git
brew search tree
brew install tree
brew search android-platform-tools
brew cask install android-platform-tools
首先要安装 zsh
(选择 zsh 而不选择 fish 主要由于它兼容性好,在这里推荐一篇zsh 开发指南,写的很详细了,感兴趣的能够去看看),老样子:linux
brew search zsh
brew install zsh
chsh -s $(which zsh)
,设置为默认的 shell,这一步也能够在 iTerm2 的设置里配置
而后安装 Oh My Zsh
:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
安装经常使用插件:
zsh-autosuggestions
,自动提示插件
zsh-completions
,自动补全插件
zsh-syntax-highlighting
,高亮插件
安装:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
复制代码
配置(vi ~/.zshrc):
# 主题,详见:https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
# agnoster
ZSH_THEME="agnoster"
# set 256color
export TERM=xterm-256color
# 插件,https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
# 一些插件自带别名,例如:
# git:https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/git#aliases
# tmux:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#aliases-1
# vscode:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#vscode
plugins=(
adb
brew
git
sublime
tmux
vscode
zsh-autosuggestions
zsh-completions
zsh-syntax-highlighting
)
autoload -U compinit && compinit
# 配置别名
alias h='history'
alias j='ls -F --color 2>/dev/null || ls -FG'
alias lsd='ls --color -d *(-/DN) 2>/dev/null || ls -dG *(-/DN)'
alias ll='ls --color -Fl --time-style=long-iso 2>/dev/null || ls -FGlT'
alias la='ls --color -FA 2>/dev/null || ls -FAG'
alias lla='ls -F --color --time-style=long-iso -lA 2>/dev/null || ls -lAFGT'
alias l='ls --color --time-style=long-iso -lFh 2>/dev/null || ls -lFhGT'
alias lsc='t=(*); echo $#t; unset t'
alias lscc='t=(* .*); echo $#t; unset t'
alias g='grep'
alias gv='grep -v'
alias rd='rmdir'
alias md='mkdir -p'
alias dh='df -h'
alias psa='ps aux'
alias psg='psa | grep -v grep | grep'
alias pk='pkill'
alias pk9='pkill -9'
alias ka='killall'
alias ka9='killall -9'
alias pst='pstree'
alias mt="top -u $USER"
alias ctime='time cat'
alias wi='which'
alias redir='rmdir **/*(/^F)'
alias cpui='grep MHz /proc/cpuinfo'
alias fng='find | grep -P'
alias ua='uname -a'
alias cu='curl -L'
alias tn='telnet'
alias to='touch'
alias hig='history 1 | grep -i'
复制代码
从新载入配置文件:
source ~/.zshrc
如今基本配置完成了,最终的样子看下面这张图:
若乱码,请安装Powerline字体,而后配置下iTerm2的字体:Preferences -> Profile -> Text -> Change Font ->选择 Meslo LG S Regular for Powerline,重启便可,如图:
顺便分享一下个人配置:oh_my_zsh
补充一句:嫌弃oh-my-zsh太慢(运行time zsh -ic exit
测试速度)不想用,也能够本身配 zsh,推荐fast
=====================================
接下来,安装node
,我的习惯用nvm来管理 node 版本,也能够考虑用nvs
Nvm:
brew search nvm
brew install nvm
echo 'export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> ~/.zshrc
source ~/.zshrc
nvm install node
,默认是最新稳定版Nginx:我的推荐Homebrew Nginx
brew tap denji/nginx
brew install nginx-full --with-upload-module
nginx -V
,查看 nginx 配置下面应该来配置一下 vscode 了:
分享一下(护眼)我的配置(settings.json)
{
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[less]": {
"editor.defaultFormatter": "michelemelluso.code-beautifier"
},
"[markdown]": {
"editor.defaultFormatter": "yzhang.markdown-all-in-one"
},
"[nunjucks]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.autoIndent": false,
"editor.fontFamily": "'Meslo LG M Regular for Powerline',Consolas,Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 15,
"editor.quickSuggestions": {
"comments": true,
"other": true,
"strings": true
},
"editor.suggest.localityBonus": true,
"editor.suggest.shareSuggestSelections": true,
"editor.suggestSelection": "recentlyUsedByPrefix",
"editor.tabCompletion": "on",
"editor.tabSize": 2,
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:'\",.<>/? ",
"editor.wordWrap": "on",
"emmet.includeLanguages": {
"javascript": "javascriptreact",
"nunjucks": "html"
},
"emmet.showSuggestionsAsSnippets": true,
"emmet.triggerExpansionOnTab": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{
"autoFix": true,
"language": "typescript"
},
{
"autoFix": true,
"language": "typescriptreact"
}
],
"explorer.confirmDelete": false,
"files.associations": {
"*.html": "html",
"*.js": "javascript",
"*.json": "jsonc",
".eslintrc": "jsonc",
"njk": "nunjucks"
},
"files.autoGuessEncoding": false,
"files.eol": "\n",
"filesize.useDecimal": true,
"gitlens.advanced.messages": {
"suppressShowKeyBindingsNotice": true
},
"html.format.indentHandlebars": true,
"html.format.wrapAttributes": "aligned-multiple",
"javascript.implicitProjectConfig.experimentalDecorators": true,
"javascript.referencesCodeLens.enabled": true,
"javascript.suggest.completeFunctionCalls": true,
"javascript.validate.enable": false,
"leetcode.defaultLanguage": "javascript",
"leetcode.endpoint": "leetcode-cn",
"leetcode.nodePath": "/Users/jiangzhiguo/.nvm/versions/node/v10.15.3/bin/node",
"markdown.extension.showExplorer": true,
"markdown.extension.toc.githubCompatibility": true,
"markdownlint.config": {
"default": true,
"MD014": false,
"MD033": false,
"MD035": false,
"MD041": false,
"MD046": false
},
"prettier.endOfLine": "lf",
"prettier.jsxSingleQuote": true,
"prettier.printWidth": 120,
"prettier.singleQuote": true,
"prettier.trailingComma": "all",
"search.showLineNumbers": true,
"sync.gist": "e651e9ea7dc53556ef1d94be7736978f",
"terminal.explorerKind": "external",
"terminal.external.osxExec": "iTerm.app",
"terminal.integrated.copyOnSelection": true,
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.fontFamily": "Source Code Pro for Powerline",
"terminal.integrated.fontSize": 15,
"terminal.integrated.rendererType": "dom",
"terminal.integrated.shell.osx": "/bin/zsh",
"typescript.implementationsCodeLens.enabled": true,
"typescript.referencesCodeLens.enabled": true,
"typescript.suggest.completeFunctionCalls": true,
"vsicons.dontShowNewVersionMessage": true,
"window.zoomLevel": 0,
"workbench.colorCustomizations": {
"editorCursor.foreground": "#d41313",
"editorGutter.background": "#d7daa7",
"editorLineNumber.foreground": "#17a346"
},
"workbench.colorTheme": "Quiet Light",
"workbench.iconTheme": "vscode-icons"
}
复制代码
推荐一个json排序整理工具(强迫症福利):jsonabc
最终样式,看下图:
最后,再配一下alfred,用起来很是爽
因为免费版,功能较少,而且不能使用工做流(workflow),因此我就在网上搜了个破解版的 😁,想用的私聊我。
安装完成后:
个人我的习惯用 ⌘ + space 来搜索,因此要先关闭默认的聚焦快捷键
设置 alfred 快捷键
Features 设置
-- This is v0.7 of the custom script for AlfredApp for iTerm 3.1.1+
-- created by Sinan Eldem www.sinaneldem.com.tr
on alfred_script(q)
if application "iTerm2" is running or application "iTerm" is running then
run script " on run {q} tell application \"iTerm\" activate try select first window set onlywindow to true on error create window with default profile select first window set onlywindow to true end try tell the first window if onlywindow is false then create tab with default profile end if tell current session to write text q end tell end tell end run " with parameters {q}
else
run script " on run {q} tell application \"iTerm\" activate try select first window on error create window with default profile select first window end try tell the first window tell current session to write text q end tell end tell end run " with parameters {q}
end if
end alfred_script
复制代码
workflow 工做流插件(没法下载/搜不到请私信我)
简单演示一下:
【结语】:上面的教程步骤很粗鲁,而个人目的主要是罗列一些我我的感受好用软件,基本都附带了连接,能够去官网查看更详细的教程。
===🧐🧐 文中不足,欢迎指正 🤪🤪===