---
# System prepended metadata

title: 把zsh變成自己的形狀
tags: [雜筆]

---

---
tags: 雜筆
---


# 把zsh變成自己的形狀

## 參考

[超簡單！十分鐘打造漂亮又好用的 zsh command line 環境](https://medium.com/statementdog-engineering/prettify-your-zsh-command-line-prompt-3ca2acc967f)

## 檔案

.zshrc
```
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh



# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="powerlevel9k/powerlevel9k"

POWERLEVEL9K_MODE='nerdfont-complete'
# command line 左邊想顯示的內容
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_writable vcs newline context) # <= left prompt 設了 "dir"

# command line 右邊想顯示的內容
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=() # <= right prompt 設了 "time"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  git
)

source $ZSH/oh-my-zsh.sh

#show mac info
#archey


export PATH=/usr/local/bin:$PATH

```

## MAC


*內含許多不完整的東東，可能需要某些前置作業，僅供參考*



* 安裝zsh
  `sudo apt-get install zsh`
  
* 設成預設shell
  `chsh -s /bin/zsh`
* 修改passwd文件
  `sudo vim /etc/passwd`
  把第一行的/bin/bash改成/bin/zsh
  把最後一行的/bin/bash改成/bin/zsh
  
* 安裝oh-my-zsh
  `sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"`
  
  
* 安裝powerline 字型(可用其他的字型，此為其中一種)

  ```
  brew tap caskroom/fonts
  brew cask install font-sourcecodepro-nerd-font
  ```
 
* 安裝 zsh theme: powerlevel9k(可用其他的，此為我喜歡的)
  ```
  git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
  ```
  
  編輯~/.zshrc
  
  修改、增加
  ```
  ZSH_THEME="powerlevel9k/powerlevel9k"
  # command line 左邊想顯示的內容
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_writable vcs newline context) # <= left prompt 設了 "dir"
  # command line 右邊想顯示的內容
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(time) # <= right prompt 設了 "time" (我自己習慣不放東西，所以刮號裡面就換成空的)
  ```
  
  使之生效
  `exec $SHELL`
  
* 安装zsh-syntax-highlighting (讓shell語法有高亮顯示看自己有沒有打錯~)
  ```
  git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
  echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
  ```
  
  使之生效
  `source ~/.zshrc`
  
  