Mac 終端效率神技

增強各種預覽的插件

  • 預覽查看圖片分辨率&大小
  • 代碼語法高亮
  • 快速預覽zip壓縮包內容
  • 快速預覽markdown格式內容
brew cask install qlcolorcode betterzipql qlimagesize qlmarkdown

iTerm2

具體的配置網上一大堆。貼一個本人親身操刀操作過的教程

程序員經常與終端操作打交道,所以很多命令便是做成了命令行模式,在自帶的 Terminal 命令都保存在 .bash_profile 文件中,使用了 iterm2,命令都保存在 .zshrc 中。

所以我們將很多命令保存且編輯。這裏也是分享出我個人常用的配置。不斷更新,喜歡的同學可以拿去直接使用

cd ~
vim .zshrc 

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/liubinpeng/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="agnoster"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

source /Users/liubinpeng/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
plugins=(
    git
    zsh-syntax-highlighting
    zsh-autosuggestions
)

# 輸入自己常用的命令
# finder 相關指令
alias co='code ./'
alias fo='open ./'

# pod 和 xcode 工程相關指令
alias o='open *.xcodeproj'
alias po='open *.xcworkspace'
alias pru='pod repo update'
alias pi='pod install'
alias pu='pod update'
alias piu='pod install --repo-update'
alias repoanalysis='specbackwarddependency /Users/liubinpeng/.cocoapods/repos/51xianqu-xq_specs'
alias plint='pod lib lint [email protected]:client/i-New-All-Specs.git,[email protected]:client/CocoaPods-Specs.git --allow-warnings --verbose --use-libraries'
alias errorShow=' >1.log 2>&1'
# git 相關指令
alias gck='git checkout'
alias gm='git merge'
alias gb='git branch'
alias gbr='git branch -a'
alias gs='git status'
alias gc='git clone'
alias gl='git log'
alias ga='git add .'
alias gpull='git pull'
alias gpush='git push'
alias gcm='git commit -m'
alias glocalbranchPush='git push --set-upstream origin '
alias glg="git log --graph --pretty=format:'%Cred%h%Crest -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
# npm 相關指令
alias ns='npm start'
alias ni='npm install'
alias nb='npm run build'
alias nig='npm install -g '

# Vue 相關命令
alias vc='vue-init webpack' # (vue-init webpack test1)用法 vc test1

# React 
alias rc='create-react-app' #(create-react-app todolist)用法 rc todolist

# React Native 命令
alias rnc='react-native init' #(react-native init todolist)用法 rnc todolist


# 終端打開應用程序
## 瀏覽器打開
alias OpenWithSafari='open -a "/Applications/Safari.app" '
alias OpenWithChrome='open -a "/Applications/Google Chrome.app" '
## 用 Typora 打開 markdown 文件預覽寫作效果。
alias OpenMDPreview='open -a "/Applications/Typora.app" '
## 用 DB Browser for SQLite 打開 db 文件
alias OpenDB='open -a "/Applications/DB Browser for SQLite.app" '
## 用 SourceTree 打開工程
alias openSourceTree='open -a "/Applications/Sourcetree.app/" '
# Flutter 環境變量

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=/Users/liubinpeng/flutter/bin:$PATH


# Android SDK 路徑

export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/emulator
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools


# iOS 模擬器開啓
alias iOSSimulator='open -a Simulator'

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


# Node Version Manager
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
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

export N_PREFIX=/usr/local/bin/node #根據你的安裝路徑而定
export PATH=$N_PREFIX/bin:$PATH
export PATH=/Users/liubinpeng/Desktop/Github/GitWorkflow/bin:$PATH


# chrome 源碼探究
# export PATH=/Users/liubinpeng/Desktop/Tech-Research/iOS/depot_tools:$PATH


# 指定 pyhton 版本

alias python="/usr/local/Cellar/python/3.7.4/bin/python3"


# 禁止終端利用 homebrew 安裝插件時候的自動更新

alias disableHomebrewUpdate="export HOMEBREW_NO_AUTO_UPDATE=true"


# 終端翻牆相關的設置(開關開啓後稍微有點延遲)

function proxy_off(){
    unset ALL_PROXY
    echo -e "已關閉代理"
}

function proxy_on(){
    export ALL_PROXY=socks5://127.0.0.1:1081
    echo -e "已開啓代理"
}


cd ~
source .zshrc

驗證:在你的 git 項目所在的目錄的終端下輸入 glg
Git日誌

爲你的終端添加常用快捷鍵

我們經常在終端做着一些純指令的事情,天天敲、月月敲這個時間的很浪費的,一天節約5分鐘,一年節約365*5/60 = 30H。一算嚇一跳。我們每年在一些終端的指令上浪費了這麼多時間。今天記錄下如何給自己的 Mac 終端添加快捷鍵。

如果是 zsh 的話,可以編輯 .zshrc 文件裏面的內容。自帶的終端則編輯 bash_profile
腳本具體看上一條。

輸出文件目錄結構

brew install tree

用法:

  1. 我們可以在目錄遍歷時使用 -L 參數指定遍歷層級

    tree -L 2
    
  2. 如果你想把一個目錄的結構樹導出到文件 Readme.md ,可以這樣操作

    tree -L 2 >README.md //然後我們看下當前目錄下的 README.md 文件
    
  3. 只顯示文件夾

    tree -d 
    
  4. 顯示項目的層級,n表示層級數。例:顯示項目三層結構,tree -l 3

    tree -L n 
    
  5. tree -I pattern 用於過濾不想要顯示的文件或者文件夾。比如要過濾項目中的node_modules文件夾

    tree -I “node_modules”
    

瀏覽器相關

  1. 搜索

在指定的站點下搜索 inurl: jobbole.com intitle:Hybrid

「安全與隱私」中系統不顯示「任何來源」

在終端執行下面的命令

sudo spctl --master-disable

系統錯誤信息的集中展示

pod spec lint *** 2>&1|tee 1.log

經常在終端做操作,有個情況就是在 iOS 的組件庫維護的時候去檢測合法性。你會發現滿屏幕都是信息,甚至好幾頁,但是事實上錯了問題後我們去翻頁的時候發現很不方便定位問題,所以想到的就是將該過程產生的任何輸出,集中打印到一個地方去查看。代碼如上。

幾個概念:

  • 0 stdin,1 stdout,2 stderr
  • |:管道。管道的作用是提供一個通道,將上一個程序的標準輸出重定向到下一個程序作爲下一個程序的標準輸入。
  • tee:從標準輸入中讀取,並將內容寫到標準輸出以及文件中。

終端查找文件

  1. 終端查找以‘.log’結尾的文件
find . -name '*.log'
  1. 安裝 ack 包.
brew install ack

使用起來很簡單,比如 ack + 你要查找的關鍵詞,它可以將查到的結果展示在下面,有完整的文件路徑.

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-RGo2dxS1-1574222484353)(https://github.com/FantasticLBP/knowledge-kit/raw/master/assets/2019-09-30-searchTools.png)]

終端每次執行 brew install 都會更新,非常耗時,如何禁止更新。

export HOMEBREW_NO_AUTO_UPDATE=true

持續更新中…

完整版,請移步

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章