[DevOps] zsh 설치 방법 (Oh My Zsh 까지..)
[DevOps] zsh 설치 방법 (Oh My Zsh 까지..)
안녕하세요? 정리하는 개발자 워니즈입니다. 이번시간에는 리눅스 터미널에서 재미난 셋팅에 대해서 몇가지 정리를 해보려고 합니다.
필자가 2019년 말 즈음에 필자의 사내에서 세미나가 진행을 했었는데, 정확히 기억은 나지 않지만, 그때 리눅스 터미널에 대해서 소개하는 자리였었습니다.
요즘에능 확실히 bash shell 보다는 다른 쉘계열들을 많이 사용하는 것 같습니다. 그렇다면, 다른 쉘을 사용했을때 과연 어떠한 장점이 있길래 사용할까요? 그런 궁금증에서 시작해서 직접 설치하고 기능들을 하나씩 겪어가면서, 장점을 알게 되었습니다.
오늘소개 드릴내용은 zsh를 소개 드리고자 합니다.
1. zsh 란 무엇인가?
Z 셸은 상호작용 로그인 셸이자 셸 스크립트를 위한 강력한 명령 줄 인터프리터로 사용할 수 있는 유닉스 셸이다. Zsh는 bash, ksh, tcsh의 일부 기능을 포함하여 수많은 개선 사항이 갖추어진 확장형 본 셸이다.
정확하게 구글에서 검색해서 나온 설명을 그대로 붙여 넣기 했습니다. 쉽게 이야기해서 우리가 보통 사용하는 본쉘의 확장판이라고 보면 될 것 같습니다.
근데 사실 기능을 모를떄는 왜 사용해야되는지 모르겠지만, 쉽게 이야기해서 그동안 터미널 화면이 너무 딱딱했던거는 사실입니다. 그런데 zsh를 기본으로 가져가고 oh my zsh 를 설치하면, 기본적인 테마도 변경이 가능하고 그냥 딱 봐도 이쁘고 휘황찬란하다라는 말이 나옵니다.
2. 설치 방법
설치는 yum을 통해서 설치를 진행합니다.
- zsh 설치
1 2 |
$ yum install zsh |
일단 zsh 가 설치가 완료되면, 기본 쉘로 지정을 해줘야 합니다.
change shell 명령어로 변경을 합니다.
1 2 |
$ chsh -s /usr/bin/zsh |
- Oh my zsh 설치
1 2 |
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" |
oh my zsh 는 이름에서도 느껴지듯이 오! 나의 zsh 를 참으로 이쁘고 멋지게 꾸며주는 것들 이라고 보시면됩니다. 플러그인들과 여러가지 테마들을 셋팅할 수 있습니다.
oh my zsh를 설치했으면 ~/.zshrc 가 생겼을 것입니다.
- ~/.zshrc 셋팅
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# 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="/root/.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/ohmyzsh/ohmyzsh/wiki/Themes ZSH_THEME="agnoster" # 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 $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 automatically update without prompting. # DISABLE_UPDATE_PROMPT="true" # Uncomment the following line to change how often to auto-update (in days). # export UPDATE_ZSH_DAYS=13 # Uncomment the following line if pasting URLs and other text is messed up. # DISABLE_MAGIC_FUNCTIONS=true # 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 $ZSH/plugins/ # Custom plugins may be added to $ZSH_CUSTOM/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. plugins=(git zsh-autosuggestions) source $ZSH/oh-my-zsh.sh # User configuration # export MANPATH="/usr/local/man:$MANPATH" # You may need to manually set your language environment # export LANG=en_US.UTF-8 # Preferred editor for local and remote sessions # if [[ -n $SSH_CONNECTION ]]; then # export EDITOR='vim' # else # export EDITOR='mvim' # fi # Compilation flags # export ARCHFLAGS="-arch x86_64" # Set personal aliases, overriding those provided by oh-my-zsh libs, # plugins, and themes. Aliases can be placed here, though oh-my-zsh # users are encouraged to define aliases within the ZSH_CUSTOM folder. # For a full list of active aliases, run `alias`. # # Example aliases # alias zshconfig="mate ~/.zshrc" # alias ohmyzsh="mate ~/.oh-my-zsh" ##From bashrc # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' #alias dir='dir --color=auto' #alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # some more ls aliases alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' # Add an "alert" alias for long running commands. Use like so: # sleep 10; alert 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$//'\'')"' source ~/path/to/fsh/fast-syntax-highlighting.plugin.zsh [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh function fzf-view() { fzf --preview '[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null | head -500' } |
필자가 셋팅한 부분은 크게 3가지 인데, 이부분은 다음 섹션에서 정리를 해보겠습니다.
3. zsh 설정
- 테마 설정
우선 가장 눈에 들어오는거는 테마부터 바꾸고 싶었습니다.
위의 github에 들어가서 마음에 드는 theme을 선정한 뒤, zshrc 파일에서 수정을 해주면 됩니다.
1 2 |
ZSH_THEME="Theme_Name" |
save를 한 뒤, 터미널창으로 나오게 되면, 바로 반영된 것을 확인 할 수 있습니다.
1 2 3 4 5 6 |
# 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/ohmyzsh/ohmyzsh/wiki/Themes ZSH_THEME="agnoster" |
필자 같은 경우는 agnoster라는 테마를 입혔고, 실제 화면은 다음과 같습니다.
- 플러그인 설정
- zsh-autosuggetions 셋팅
123456#git clonegit clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions#zshrc 파일 수정plugins=(git zsh-autosuggestions)zshrc 파일에서 위와 같이 셋팅을 하게 되면, 플러그인이 삽입이 됩니다.
- fast-syntax-highlighting
123456#git clonegit clone https://github.com/zdharma/fast-syntax-highlighting ~/path/to/fsh#적용$ source ~/path/to/fsh/fast-syntax-highlighting.plugin.zsh
- fzf 기능 추가
이기능을 위해서 zsh 을 사용한다고 해도 과언이 아닙니다. fzf 는 현재 깃헙에서도 핫한데, 이것을 만드시분이 한국분이라고 들었습니다. 정말 대단하면서도 편리하게 해주셔서 감사하다고 전하고 싶습니다.
-설치
1 2 3 4 5 6 |
#git clone $ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf #install ~/.fzf/install |
기본적인 사용법은 위에 가보시면 설명이 잘되어있습니다.
-기능 추가
1 2 3 4 5 6 7 8 9 10 11 12 |
#zshrc 파일에 아래에 내용 추가 function fzf-view() { fzf --preview '[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (highlight -O ansi -l {} || coderay {} || rougify {} || cat {}) 2> /dev/null | head -500' } |
등록을 해둔뒤, 터미널 창에 fzf-view라고 치면 현재 폴더 하위까지 리스팅 되어서 마치 GUI환경에서 파일을 볼 수 있는 것처럼 셋팅이 됩니다 .
왼쪽이 리스팅된 파일 목록이고 우측 화면에서 내용을 보여주고 있습니다. 매번 vi로 파일을 열어 볼 필요 없이 바로바로 볼 수 있어서 너무나도 편리한 것 같습니다.
4. 마치며…
아직 기초적인 셋팅만 해두고 사용하고 있습니다. 좀더 터미널을 이쁘고 멋있게 셋팅을 하여 사용해보고 싶습니다. 우선 fzf만으로도 다음번 정리할 포스팅이 있을 것 같습니다. 그리고 zsh에 대한 플러그인도 좀더 뜯어보고 정리를 하려고 합니다.
[참고 블로그]
[FZF로 ZSH 터미널 더 강력하게 사용하기](