背景
最近公司新購置了好幾臺 Linux 服務器然后配置一些服務的時候很不習慣,估計是我平時自己的 zsh + oh-my-zsh 用多了,故想整理下 .bash_rc
和 .zshrc
我個人的一些配置,這些配置包含了一些 alias
快捷命令和命令行系統配置,可以讓終端變得快捷易用,今晚再寫個 shell 腳本實現快速修改 .bash_rc
的配置。
.bash_rc/.zshrc
配置匯總
-
終端不自動執行命令
# If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac
-
.bash_history
文件(同理.zsh_history
)不重寫而是使用附加模式記錄命令# append to the history file, don't overwrite it shopt -s histappend
-
增加
.bash_history
、.zsh_history
文件記錄閾值,超過閾值后自動清空HISTFILESIZE=2000
-
根據命令行長短自動調節終端行列顯示排版
# check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize
-
開啟適合編程的命令行提示 feature
if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi
-
常用的 alias 聲明 — 簡寫部分
比較容易懂。
alias cls='clear' alias vi='vim' alias ll='ls -l' alias la='ls -a'
-
常用的 alias 聲明 — 效果增強部分
這部分讓 ls 和 grep 都帶有關鍵字亮色的提示,讓 alert 提示的錯誤信息在終端中顯示起來更友好。
alias ls='ls --color=auto' alias grep='grep --color=auto' alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
-
常用的 alias 聲明 — 效果增強部分2
這部分增加了在 MacOS 系統中顯示和隱藏文件的快捷命令,和在終端中切換 bash 和 zsh 的快捷命令。
alias showfile='defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finde r' alias hidefile='defaults write com.apple.finder AppleShowAllFiles -boolean false ; killall Find er' alias switchbash='chsh -s /bin/bash' alias switchzsh='chsh -s /bin/zsh'
全部的配置匯總如上,一是方便我自己做個備份,二是大家可以按需使用。