Mac OS 打造完美終端

先看效果圖:


終端效果圖.jpg

1. 安裝 homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. 安裝 tmux

brew install tmux
brew install reattach-to-user-namespace 

3. 配置 tmux (vim ~/.tmux.conf)

# Sets prefix globally


# Reload tmux.conf
bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"

# set global config -------------------------------- 
set-option -g default-terminal "screen-256color"
set-option -g status-keys "emacs"
set-option -g escape-time 0
set-option -g base-index 1
set-option -g mouse on
set-option -qwg utf8 on

# Easily go to tmux choose-tree to navigate between sessions
 bind-key w choose-tree

# Smart pane switching with awareness of vim splits
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim='echo "#{pane_current_command}" | grep -iqE "(^|\/)g?(view|n?vim?x?)(diff)?$"'
bind -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"

# window config --------------------------------
set -wg allow-rename off
set -wg automatic-rename off
set -wg renumber-windows on
bind-key a last
# kill pane (prefix q)
bind-key q killp
# kill window (prefix Ctrl+q)
bind-key C-q killw

# retain current path
bind-key c new-window -c "#{pane_current_path}"
bind-key % split-window -h -c "#{pane_current_path}"
bind-key '"' split-window -c "#{pane_current_path}"

# Resize panes using shift key
bind -n S-Left resize-pane -L 2
bind -n S-Right resize-pane -R 2
bind -n S-Down resize-pane -D 1
bind -n S-Up resize-pane -U 1

# copy setting --------------------------------
setw -g mode-keys vi
# buffer緩存復制到Mac系統(tǒng)粘貼板
bind-key C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
# Mac系統(tǒng)粘貼板內(nèi)容復制到會話
bind-key C-v run "reattach-to-user-namespace pbpaste | tmux load-buffer - \; paste-buffer -d"
# 綁定y鍵為復制選中文本到Mac系統(tǒng)粘貼板
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'
# 鼠標拖動選中文本,并復制到Mac系統(tǒng)粘貼板
bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel "pbcopy"

# ------ status theme -------------------------------
set -g message-style "bg=#778800, fg=#ffffdd"        # tomorrow night blue, base3

# alignment
#set-option -g status-justify centre
set -g status-style "bg=#003366, fg=#ffffdd"   # tomorrow night blue, base3
set -g status-left "#[bg=#0088ff] ? #S "       # blue
set -g status-left-length 400
set -g status-right "#{?client_prefix, ? , } #[bg=#00346e]#(whoami)@#h %Y-%m-%d %H:%M"
set -g status-right-length 600

set -wg window-status-format " #I: #W "
set -wg window-status-separator ""
set -wg window-status-attr dim
set -wg window-status-current-format " #I #W #F "
set -wg window-status-current-attr bold
set -wg window-status-current-style "bg=#778800"
set -wg window-status-last-style "fg=#aabbcc"

set -wg pane-active-border-style "fg=#aabbcc,bg=#555555"
set -wg pane-border-style "fg=#d6d6d6"

4. 配置 vim (vim ~/.vimrc)

"colorscheme darkblue " 設(shè)定配色方案
syntax on " 自動語法高亮
set nocompatible " 關(guān)閉 vi 兼容模式
set number " 顯示行號

" Highlight current line
highlight CursorLine   cterm=NONE ctermbg=black ctermfg=NONE guibg=NONE guifg=NONE
highlight Search cterm=NONE ctermbg=brown ctermfg=white guibg=NONE guifg=NONE
"highlight CursorColumn cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
set cursorline " 突出顯示當前行

set hlsearch "設(shè)置搜索高亮
set ruler " 打開狀態(tài)欄標尺
set shiftwidth=4 " 設(shè)定 << 和 >> 命令移動時的寬度為 4
set softtabstop=4 " 使得按退格鍵時可以一次刪掉 4 個空格
set tabstop=4 " 設(shè)定 tab 長度為 4
set nobackup " 覆蓋文件時不備份
set autochdir " 自動切換當前目錄為當前文件所在的目錄
set nocompatible              " be iMproved, required

"# 解決終端粘貼Tab錯位問題
if &term =~ "xterm.*"
    let &t_ti = &t_ti . "\e[?2004h"
    let &t_te = "\e[?2004l" . &t_te
    function XTermPasteBegin(ret)
        set pastetoggle=<Esc>[201~
        set paste
        return a:ret
    endfunction
    map <expr> <Esc>[200~ XTermPasteBegin("I")
    imap <expr> <Esc>[200~ XTermPasteBegin("")
    cmap <Esc>[200~ <nop>
    cmap <Esc>[201~ <nop>
endif

5. 安裝 fasd

## homebrew 貌似也能安裝
git clone https://github.com/clvv/fasd.git
make install

6. 配置終端環(huán)境 (vim ~/.bash_profile)

#   Basic alias 
#   -----------------------------------------------------
alias rm='rm -I'
alias cp='cp -iv'
alias mv='mv -iv'
alias ll='ls -lF'
alias la='ls -aAF'
alias l='ls -lF'
alias c='clear'
alias path='echo -e ${PATH//:/\\n}'
eval "$(fasd --init auto)"
alias v='f -e vim'

#   golang & git alias
#   -----------------------------------------------------
alias gitl='git log --pretty=format:"%h - %Cgreen[%ar]%Creset %Cred%an%Creset %Cblue?%Creset %s"'
alias gitb='git branch -vv'
alias gitg='gitl --graph'
alias gitr='git remote -v'
alias gitd='git diff --stat'
alias gits='git status'

export LS_OPTIONS='--color=auto' # 如果沒有指定,則自動選擇顏色
export CLICOLOR='Yes' #是否輸出顏色

export JAVA_HOME="$(/usr/libexec/java_home)"
export CLASS_PATH="$JAVA_HOME/lib"

export PATH='/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/go/bin:/Users/jason/Gopath/bin'
export GOROOT='/usr/local/go'
export GOARCH='amd64'
export GOOS='darwin'
export GOPATH='/Users/Jason/Gopath'

. ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
#export PS1='? \W$(__git_ps1 " \033[1;34mgit:(\e[0m\033[1;31m %s \e[0m\033[1;34m)\e[0m")\033[1;32m ?  \e[0m'
export PS1='? \W\[\e[1;31m\]$(__git_ps1 " ( %s )")\[\e[m\] ?  '
#export PS2="| => "

#  extention alias
#  ------------------------------------------------------
alias tree='tree -CN'

#   memHogsTop, memHogsPs:  Find memory hogs
#   -----------------------------------------------------
alias memHogsTop='top -l 1 -o rsize | head -20'
alias memHogsPs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10'

#   cpuHogs:  Find CPU hogs
#   -----------------------------------------------------
alias cpu_hogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10'

#   topForever:  Continual 'top' listing (every 10 seconds)
#   -----------------------------------------------------
alias topForever='top -l 9999999 -s 10 -o cpu'

#   ttop:  Recommended 'top' invocation to minimize resources
#   ------------------------------------------------------------
#       Taken from this macosxhints article
#       http://www.macosxhints.com/article.php?story=20060816123853639
#   ------------------------------------------------------------
alias ttop="top -R -F -s 10 -o rsize"

#   cleanupDS:  Recursively delete .DS_Store files
#   -------------------------------------------------------------------
alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"

#   cleanupLS:  Clean up LaunchServices to remove duplicates in the "Open With" menu
#   -----------------------------------------------------------------------------------
alias cleanupLS="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"

#   ---------------------------------------
#   WEB DEVELOPMENT
#   ---------------------------------------
alias editHosts='sudo vim /etc/hosts'                  # editHosts:        Edit /etc/hosts file

function addKeyToAgent() {
    #eval "$(ssh-agent -s)"
    ssh-add -K ~/.ssh/id_rsa
}

補充說明

  • fasd 的使用,大家自行百度,大大提升工作效率。
  • git配置時,需要找到.git-prompt.sh文件(git安裝完查找此文件),Copy到 ~/ 下,git的常用命令做了 alias 和輸出優(yōu)化,很Cool的。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容

  • macvim配置 最終效果如下: 系統(tǒng)環(huán)境 macos10.12.4 homebrew1.2.1 python3....
    Like_eb56閱讀 69,799評論 5 65
  • Ubuntu的發(fā)音 Ubuntu,源于非洲祖魯人和科薩人的語言,發(fā)作 oo-boon-too 的音。了解發(fā)音是有意...
    螢火蟲de夢閱讀 99,539評論 9 467
  • 本來就沒有什么不開心, 偶爾的煩惱亦是生活的組成 一切似乎都已經(jīng)注定, 一切似乎又都可以重來 關(guān)鍵不在世界的改變,...
    遠曉閱讀 272評論 0 0
  • ——歲月于無聲處流逝,我們于喧鬧處成長 兩年前第一次踏入小鎮(zhèn)時,所有的一切對于我來說都是陌生且新鮮的。第一次嘗試著...
    呆小瓶閱讀 371評論 0 2
  • 妙女士,三十歲,著名外企人事經(jīng)理,月薪三萬。 從十八歲到S城讀書,妙女士用了十二年時間,從一無所有到有房有車...
    老醋322閱讀 802評論 4 6