先看效果图:
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系统粘贴板
bind-key C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
# Mac系统粘贴板内容复制到会话
bind-key C-v run "reattach-to-user-namespace pbpaste | tmux load-buffer - \; paste-buffer -d"
# 绑定y键为复制选中文本到Mac系统粘贴板
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel 'reattach-to-user-namespace pbcopy'
# 鼠标拖动选中文本,并复制到Mac系统粘贴板
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 " 设定配色方案
syntax on " 自动语法高亮
set nocompatible " 关闭 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 "设置搜索高亮
set ruler " 打开状态栏标尺
set shiftwidth=4 " 设定 << 和 >> 命令移动时的宽度为 4
set softtabstop=4 " 使得按退格键时可以一次删掉 4 个空格
set tabstop=4 " 设定 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=[201~
set paste
return a:ret
endfunction
map [200~ XTermPasteBegin("I")
imap [200~ XTermPasteBegin("")
cmap [200~
cmap [201~
endif
5. 安装 fasd
## homebrew 貌似也能安装
git clone https://github.com/clvv/fasd.git
make install
6. 配置终端环境 (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 和输出优化,很Cool的。