樹莓派提高shell逼格oh-my-zsh

weixin_34116110發表於2017-09-04

20170904 初成文,未完...

20171012 更新外掛及alias方案

技術可以菜,但寫程式碼的方式一定要帥!

7439293-1c8513bc65baa769.png
powerline主題

檢視當前系統可用的shell

cat /etc/shells

“Shell是Linux/Unix的一個外殼,你理解成衣服也行。它負責外界與Linux核心的互動,接收使用者或其他應用程式的命令,然後把這些命令轉化成核心能理解的語言,傳給核心,核心是真正幹活的,幹完之後再把結果返回使用者或應用程式。

Linux/Unix提供了很多種Shell,為毛要這麼多Shell?難道用來炒著吃麼?那我問你,你同型別的衣服怎麼有那麼多件?花色,質地還不一樣。寫程式比買衣服複雜多了,而且程式設計師往往負責把複雜的事情搞簡單,簡單的事情搞複雜。牛程式設計師看到不爽的Shell,就會自己重新寫一套,慢慢形成了一些標準,常用的Shell有這麼幾種,sh、bash、csh等”    --摘自網上

zsh強大之處在於命令補全,可以補齊路徑,補齊命令,補齊引數等,只需按TAB鍵;另外還有跳轉目錄、萬用字元搜尋、別名、歷史記錄等等...還有幾百種外掛擴充

一、安裝前需要先安裝zsh

sudo apt install zsh

二、兩種下載方式,擇其一

1、通過wget下載安裝指令碼

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

2、通過curl下載安裝指令碼

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

三、更換主題及部分引數說明

sudo nano ~/.zshrc

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

export TERM=xterm-256color    //使終端支援256色,tput colors或echo $TERM顯示是否正確開啟

ZSH_THEME="agnoster"    //改為random會在每次開啟終端或執行zsh隨機選擇一種主題風格

plugins=(git autojump zsh-syntax-highlighting)  //使用的外掛

DISABLE_AUTO_UPDATE="true"  //關閉自動更新

ENABLE_CORRECTION="true" //開啟智慧更正選項

CASE_SENSITIVE="true" //對大小寫敏感

alias g='git'  //別名設定

四、使用agnoster主題時依賴powerline字型,安裝缺失字型

wget https://raw.githubusercontent.com/powerline/powerline/develop/font/10-powerline-symbols.conf

wget https://raw.githubusercontent.com/powerline/powerline/develop/font/PowerlineSymbols.otf

sudo mkdir /usr/share/fonts/OTF

sudo cp 10-powerline-symbols.conf /usr/share/fonts/OTF/

sudo mv 10-powerline-symbols.conf /etc/fonts/conf.d/

sudo mv PowerlineSymbols.otf /usr/share/fonts/OTF/

五、切換預設shell

chsh -s /bin/zsh

六、外掛

ls ~/.oh-my-zsh/plugins    //列出內建可用外掛

直接在~/.zshrc裡新增即可,部分需要安裝,比如指令高亮外掛:

git clone git://github.com/jimmijj/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting

plugins=(zsh-syntax-highlighting)  //終端命令提示,正確為綠色,錯誤為紅色

我自己使用的外掛(僅供參考):

plugins=(git sudo colored-man-pages last-working-dir command-not-found zsh-syntax-highlighting zsh-autosuggestions autojump command-time alias-tips you-should-use debian dirhistory) 

sudo //忘了加sudo只需按兩下Esc鍵

colored-man-pages //man手冊頁面,高亮版,更容易閱讀

last-working-dir //返回上次開啟終端的目錄

command-time //顯示某命令執行完成所用的時間

zsh-autosuggestions //根據使用習慣自動顯示建議,按→補充

alias-tips //提示可用的alias

zsh-you-should-use //與上面類似,提示可用的alias,可配置

dirhistory //使用alt+左右方向鍵來切換歷史上級或下級目錄

上面需自行安裝的外掛:

git clone git://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions

git clone https://github.com/popstas/zsh-command-time.git ~/.oh-my-zsh/custom/plugins/command-time

git clone https://github.com/MichaelAquilina/zsh-you-should-use.git ~/.oh-my-zsh/custom/plugins/you-should-use

git clone https://github.com/djui/alias-tips.git ~/.oh-my-zsh/custom/plugins/alias-tips

七、別名方案(參考,可按個人使用習慣自行修改)

alias wget="wget -c"

alias du="du -h"

alias df="df -Th"

alias cp="cp -iv"

alias mv="mv -iv"

alias rm="rm -iv"

alias ls="ls -F --color=auto"

alias ll="ls -alF"

alias la="ls -aF"

#下面這個是按大小排序,僅顯示大小和檔名,不顯示其他資訊

alias lll="ls -AlhF --sort=size . | tr -s " " | cut -d " " -f 5,9"

alias grep="grep --color=auto'

#輸出當前目錄size最大的10個資料夾

alias dumax="du -hsx * | sort -rh | head -10"

alias fm="free -m"

alias ua="uname -a"

alias acs="apt-cache search"

alias ats="sudo aptitude show"

alias ati="sudo aptitude install"

alias aud="sudo aptitude update && sudo aptitude upgrade"






參考文章:

你好,Oh My Zsh - 社群力量全新方式定義命令列

分享一下,你們都用了什麼 oh my zsh 外掛?

Linux終極shell-Z Shell--用強大的zsh & oh-my-zsh把Bash換掉

相關文章