zsh和oh-my-zsh安装

Posted 谁说我是二师兄

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zsh和oh-my-zsh安装相关的知识,希望对你有一定的参考价值。

一、安装:

1、安装zsh

  sudo apt-get install zsh

2、把默认的Shell改成zsh

  chsh -s /bin/zsh

  注意:不要使用sudo。

3、如果总是报 chsh: PAM: Authentication failure, 则需配置密码文件,解决chsh: PAM认证失败的问题

  sudo vim /etc/passwd

  把第一行的/bin/bash改成/bin/zsh,这个是root用户的。

  把当前用户的/bin/bash改成/bin/zsh,一般安装后默认已经是zsh。

4、安装oh-my-zsh

  git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

官网:http://ohmyz.sh/

5、重启电脑,查看效果

 

6.安装自动补全插件incr

  创建~/.oh-my-zsh/plugins/incr/incr-0.2.zsh,输入一下脚本

# Incremental completion for zsh
# by y.fujii <y-fujii at mimosa-pudica.net>, public domain


autoload -U compinit
zle -N self-insert self-insert-incr
zle -N vi-cmd-mode-incr
zle -N vi-backward-delete-char-incr
zle -N backward-delete-char-incr
zle -N expand-or-complete-prefix-incr
compinit

bindkey -M viins ‘^[‘ vi-cmd-mode-incr
bindkey -M viins ‘^h‘ vi-backward-delete-char-incr
bindkey -M viins ‘^?‘ vi-backward-delete-char-incr
bindkey -M viins ‘^i‘ expand-or-complete-prefix-incr
bindkey -M emacs ‘^h‘ backward-delete-char-incr
bindkey -M emacs ‘^?‘ backward-delete-char-incr
bindkey -M emacs ‘^i‘ expand-or-complete-prefix-incr

unsetopt automenu
compdef -d scp
compdef -d tar
compdef -d make
compdef -d java
compdef -d svn
compdef -d cvs

# TODO:
#     cp dir/

now_predict=0

function limit-completion
{
	if ((compstate[nmatches] <= 1)); then
		zle -M ""
	elif ((compstate[list_lines] > 6)); then
		compstate[list]=""
		zle -M "too many matches."
	fi
}

function correct-prediction
{
	if ((now_predict == 1)); then
		if [[ "$BUFFER" != "$buffer_prd" ]] || ((CURSOR != cursor_org)); then
			now_predict=0
		fi
	fi
}

function remove-prediction
{
	if ((now_predict == 1)); then
		BUFFER="$buffer_org"
		now_predict=0
	fi
}

function show-prediction
{
	# assert(now_predict == 0)
	if
		((PENDING == 0)) &&
		((CURSOR > 1)) &&
		[[ "$PREBUFFER" == "" ]] &&
		[[ "$BUFFER[CURSOR]" != " " ]]
	then
		cursor_org="$CURSOR"
		buffer_org="$BUFFER"
		comppostfuncs=(limit-completion)
		zle complete-word
		cursor_prd="$CURSOR"
		buffer_prd="$BUFFER"
		if [[ "$buffer_org[1,cursor_org]" == "$buffer_prd[1,cursor_org]" ]]; then
			CURSOR="$cursor_org"
			if [[ "$buffer_org" != "$buffer_prd" ]] || ((cursor_org != cursor_prd)); then
				now_predict=1
			fi
		else
			BUFFER="$buffer_org"
			CURSOR="$cursor_org"
		fi
		echo -n "\e[32m"
	else
		zle -M ""
	fi
}

function preexec
{
	echo -n "\e[39m"
}

function vi-cmd-mode-incr
{
	correct-prediction
	remove-prediction
	zle vi-cmd-mode
}

function self-insert-incr
{
	correct-prediction
	remove-prediction
	if zle .self-insert; then
		show-prediction
	fi
}

function vi-backward-delete-char-incr
{
	correct-prediction
	remove-prediction
	if zle vi-backward-delete-char; then
		show-prediction
	fi
}

function backward-delete-char-incr
{
	correct-prediction
	remove-prediction
	if zle backward-delete-char; then
		show-prediction
	fi
}

function expand-or-complete-prefix-incr
{
	correct-prediction
	if ((now_predict == 1)); then
		CURSOR="$cursor_prd"
		now_predict=0
		comppostfuncs=(limit-completion)
		zle list-choices
	else
		remove-prediction
		zle expand-or-complete-prefix
	fi
}

 7. 在~/.zshrc中添加incr插件,具体配置可参考.zshrc配置

  

以上是关于zsh和oh-my-zsh安装的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu配置zsh和oh-my-zsh

zsh和oh-my-zsh安装

CentOS7.5安装配置Oh-My-Zsh

oh-my-zsh 安装及使用

Linux 安装 zsh & oh-my-zsh

UOS-deepin设置zsh和oh-my-zsh