終端配置總結

背景

最近公司新購置了好幾臺 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'
    

全部的配置匯總如上,一是方便我自己做個備份,二是大家可以按需使用。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容