Mac下配置alias,zsh終端命令別名

Mac下配置alias,zsh終端命令別名

     經常使用命令行進行一些操作,一些常用的命令一遍遍的敲比較浪費時間,想通過別名的方式簡化操作。

1、就是編輯~/.bash_profile,比如添加PS:=兩邊沒有空格

    alias st="git status"
    alias pull='git pull'
    alias push='git push'
    alias add='git add .'
    alias ci='git commit -m'
    alias co='git checkout'
    alias myip="ifconfig | grep '192'"
    alias fetch=' git fetch upstream'
    alias merge='git merge'

PS:如果沒有.bash_profile文件,那就直接創建一個.bash_profile,然後進行編輯。

    touch .bash_profile
    vim .bash_profile

2、按照正常的邏輯直接執行(或者重啓一下終端)。

    source ~/.bash_profile

就可以了。

     但是我的電腦沒有成功。主要原因我使用的是zsh,相應配置了oh-my-zsh。那麼以上的管理配置會發現無效,因爲配置了zsh之後,打開新的終端不會按照bash的方式走 .bash_profile,source ~/.bash_aliases沒有執行,因此發現就沒有起作用。而是走了.zshrc文件。

     解決方案較多,可以直接在.zshr當中可以設置aliases 。但是這樣感覺不太好,怪怪的,但是~/.bash_profile中的設置又不會生效。

     所以:推薦在在.zshrc文件的開頭添加這樣一行語句

    test -f ~/.bash_profile  && source ~/.bash_profile

然後重啓一下zsh

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章