背景: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 工做流插件(沒法下載/搜不到請私信我)
簡單演示一下:
這些基本就夠用了。【結語】:上面的教程步驟很粗魯,而個人目的主要是羅列一些我我的感受好用軟件,基本都附帶了連接,能夠去官網查看更詳細的教程。
===🧐🧐 文中不足,歡迎指正 🤪🤪===