iterm2 bash 配置

iterm2 使用bash做爲默認shell

  1. 查看安裝了那些shell
    chsh -l 或者 cat /etc/shellslinux

  2. 查看當前使用的shellshell

    echo $SHELLvim

  3. 更改bash爲默認shell
    chsh -s /bin/bash //須要用戶輸入密碼bash

iterm2 bash配置

  1. 建立bash配置文件
    vim ~./bash_profile.net

  2. 在配置文件中配置相關參數
    export CLICOLOR=1 //設置使用顏色
    export PS1="\[\e[35m\]Hello\[\e[0m\]$ \[\e[31m\]\t\[\e[0m\] [\[\e[36m\]\w\[\e[0m\]] \[\e[32m\]\u\[\e[0m\]\[\e[33m\]@\[\e[0m\]\[\e[34m\]net\[\e[0m\]\$ " //配置顯示格式
    注: PS1中若是配置有非打印的轉意符(好比顏色),必須用\[ xxx \]包括起來,不然會引發字符長度計算錯誤,致使命令過長時不換行(而是從本行開頭進行覆蓋)問題。
    參考:
    Make sure all non-printable bytes in your PS1 are contained within \[ \]. Otherwise, bash will count them in the length of the prompt. It uses the length of the prompt to determine when to wrap the line.
    See http://mywiki.wooledge.org/BashFAQ/053
    (若是正確設置PS1後依然出現命令行過長時在本行覆蓋的問題,能夠在_設置PS1前_添加 stty columns 1000 )命令行

PS1中經常使用變量含義

  1. 轉意變量
    \d :表明日期,格式爲weekday month date
    \H :完整的主機名
    \h :主機的第一個名字
    \t :顯示時間爲24小時格式(HH:MM:SS)
    \T :顯示時間爲12小時格式
    \A :顯示時間爲24小時格式(HH:MM)
    \u :當前用戶的帳戶名
    \v :BASH的版本信息
    \w :完整的工做目錄名
    \W :利用basename取得工做目錄名稱,因此只會列出最後一個目錄
    \# :第幾個命令
    \$ :提示字符,若是是root時,提示符爲:#;普通用戶爲:$blog

  2. 顏色表變量
    前景 背景 顏色
    30 40 黑色
    31 41 紅色
    32 42 綠色
    33 43 黃色
    34 44 藍色
    35 45 紫紅色
    36 46 青藍色
    37 47 白色get

  3. 其餘變量
    0 OFF
    1 高亮顯示
    4 underline
    7 反白顯示
    8 不可見it

  4. 顏色設置
    設置顏色: \e[?m //?是顏色表值
    取消顏色設置: \e[mtable

參考

http://blog.csdn.net/zhangxuechao_/article/details/52016770
http://flytreeleft.iteye.com/blog/1541616
http://roclinux.cn/?p=739

相關文章
相關標籤/搜索