Zsh :: oh-my-zsh

Published by onesixx on

http://www.zsh.org/
https://github.com/robbyrussell/oh-my-zsh/
https://github.com/robbyrussell/oh-my-zsh/wiki/themes
https://spyrosoft.com/blog/why-to-switch-from-bash-to-zsh.html
http://coding-korea.blogspot.kr/2012/09/zsh.html?m=1
http://zsh.sourceforge.net/Guide/zshguide.pdf
https://onesixx.com/zsh/
https://onesixx.com/iterm/
https://onesixx.com/vim/

Zsh 설치 이유

  • a shell designed for interactive use, although it is also a powerful scripting language.
  • 맥 iTerm, Ubuntu 터미널 앱 같은 환경으로 맞추기 위해 ..

현재 환경

### 현재 Shell 확인
$ echo $0
$ echo $SHELL
/bin/zsh

### 현재 Shell 위치 
$ which zsh                                                                     ✔ │ base 
/bin/zsh

### 버전 확인
$ zsh --version                                                                 ✔ │ base 
zsh 5.8 (x86_64-apple-darwin20.0)

$ ls -al ~ | grep .z                                                            ✔ │ base 
drwxr-xr-x  21 onesixx  staff    672 Sep 11 22:11 .oh-my-zsh
-rw-r--r--   1 onesixx  staff  85717 Sep 13 16:05 .p10k.zsh
-rw-r--r--   1 onesixx  staff  48094 Sep 13 16:15 .zcompdump-sixxCC-5.8
-rw-------   1 onesixx  staff  15140 Sep 16 12:35 .zsh_history
drwx------  23 onesixx  staff    736 Sep 15 23:33 .zsh_sessions
-rw-r--r--   1 onesixx  staff   4842 Sep 13 16:12 .zshrc

# 기본 sh 변경
chsh -s $(which zsh)

Zsh 설정 파일 로딩 순서 

  /etc/zsh/zshenv  –> /etc/zsh/zprofile   –>  /etc/zsh/zshrc    –>  /etc/zsh/zlogin

~/.zshenv  –> ~/.zprofile  –> ~/.zlogin –> ~/.zshrc

.zshenv

Since .zshenv is always sourced, it often contains exported variables that should be available to other programs.
For example, $PATH, $EDITOR, and $PAGER are often set in .zshenv.
Also, you can set $ZDOTDIR in .zshenv to specify an alternative location for the rest of your zsh configuration.

.zshrc

is for interactive shell configuration. You set options for the interactive shell there with the setopt and unsetopt commands. You can also load shell modules, set your history options, change your prompt, set up zle and completion, et cetera. You also set any variables that are only used in the interactive shell (e.g. $LS_COLORS).

.zlogin

is sourced on the start of a login shell. This file is often used to start X using startx.
Some systems start X on boot, so this file is not always very useful.
.zlogin is sourced after .zshrc

.zprofile

is basically the same as .zlogin except that it’s sourced directly before .zshrc is sourced instead of directly after it.
According to the zsh documentation, “.zprofile is meant as an alternative to `.zlogin’ for ksh fans; the two are not intended to be used together, although this could certainly be done if desired.”

.zlogout

is sometimes used to clear and reset the terminal.
You should go through the configuration files of random Github users to get a better idea of what each file should contain.

oh-my-zsh

http://ohmyz.sh/

$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Themes

https://github.com/robbyrussell/oh-my-zsh/wiki/Themes 에 여러 테마를 고를수 있다. 

Powerlevel10k (Oh My Zsh에 적용 가능한 테마중 하나)

https://github.com/romkatv/powerlevel10k

$ git clone https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
$ source ~/powerlevel10k/powerlevel10k.zsh-theme
$ p10k configure

잘못 선택했다면 p10k.zsh 라는 파일을 지우면 다시 설정할 수 있게 해준다.

Enabling Plugins

https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
Plugins을 설치하면서 추가기능 사용 (~/.oh-my-zsh/plugins/*)

vi /.zshrc

54번째줄 

plugins=(git sublime)

Using Plugins

Most plugins (should! we’re working on this) include a README, which documents how to use them.

편의성

cd …. 부모의 부모 디렉토리로 이동

cd –     이전 히스토리 .

oh-my-zsh 플러그인

0. oh-my-zsh의  기본 플러그인

1. 명령어 하이라이팅 플러그인 – zsh-syntax-highlighting

# 설치
brew install zsh-syntax-highlighting

# 적용
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# .zshrc에 추가 (항상 실행 설정)
위 내용을 ~/.zshrc 맨아래 추가 

2. 자동완성 플러그인 –  zsh-autosuggestions

 suggestion이 나오면 방향키 오른쪽 을 이용하면 자동 완성이 됩

# 설치
$ brew install fzf

#To install useful keybindings and fuzzy completion:
$ /usr/local/opt/fzf/install

# 적용
$ source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

# .zshrc에 추가 (항상 실행 설정)
위 내용을 ~/.zshrc 맨아래 추가 

3. Commandline fuzzy finder 플러그인 –  fzf

기본적인 기능

# 설치
brew install zsh-autosuggestions

# 적용
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

# 파이프라인을 이용하는 방법
find * -type f | fzf > selected

에러

paste 에러

https://cirw.in/blog/bracketed-paste

~/.zshrc에 ADD

# Code from Mikael Magnusson: http://www.zsh.org/mla/users/2011/msg00367.html
#
# Requires xterm, urxvt, iTerm2 or any other terminal that supports bracketed
# paste mode as documented: http://www.xfree86.org/current/ctlseqs.html

# create a new keymap to use while pasting
bindkey -N paste
# make everything in this keymap call our custom widget
bindkey -R -M paste "^@"-"\M-^?" paste-insert
# these are the codes sent around the pasted text in bracketed
# paste mode.
# do the first one with both -M viins and -M vicmd in vi mode
bindkey '^[[200~' _start_paste
bindkey -M paste '^[[201~' _end_paste
# insert newlines rather than carriage returns when pasting newlines
bindkey -M paste -s '^M' '^J'

zle -N _start_paste
zle -N _end_paste
zle -N zle-line-init _zle_line_init
zle -N zle-line-finish _zle_line_finish
zle -N paste-insert _paste_insert

# switch the active keymap to paste mode
function _start_paste() {
  bindkey -A paste main
}

# go back to our normal keymap, and insert all the pasted text in the
# command line. this has the nice effect of making the whole paste be
# a single undo/redo event.
function _end_paste() {
#use bindkey -v here with vi mode probably. maybe you want to track
#if you were in ins or cmd mode and restore the right one.
  bindkey -e
  LBUFFER+=$_paste_content
  unset _paste_content
}

function _paste_insert() {
  _paste_content+=$KEYS
}

function _zle_line_init() {
  # Tell terminal to send escape codes around pastes.
  [[ $TERM == rxvt-unicode || $TERM == xterm || $TERM = xterm-256color || $TERM = screen || $TERM = screen-256color ]] && printf '\e[?2004h'
}

function _zle_line_finish() {
  # Tell it to stop when we leave zle, so pasting in other programs
  # doesn't get the ^[[200~ codes around the pasted text.
  [[ $TERM == rxvt-unicode || $TERM == xterm || $TERM = xterm-256color || $TERM = screen || $TERM = screen-256color ]] && printf '\e[?2004l'
}

Categories: Ubuntu

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x