当前位置:   article > 正文

zsh shell linux开发利器_linux zsh

linux zsh

zsh shell 安装

首先,查看linux系统自带哪些shell

cat /etc/shells
  • 1

1.安装zsh:

  sudo apt-get install zsh
  • 1

编译
没有root权限的用户,也可以通过源码安装(安装到自己的目录)
在官网下载源码包:https://sourceforge.net/projects/zsh/

tar -zxvf zsh-5.7.1.tar.xz
cd zsh-5.7.1
mkdir install
./configure --prefix=/public/home/xxxx/install/zsh-5.7.1/install
make && make install 
  • 1
  • 2
  • 3
  • 4
  • 5

将默认shell切换为zsh
在/.bashrc 最后面写入,每次默认启动zsh

exec /public/home/jiahao/install/zsh-5.7.1/install/bin/zsh
alias zsh=/public/home/jiahao/install/zsh-5.7.1/install/bin/zsh
  • 1
  • 2

2.确认是否安装成功

  zsh --version
  • 1

3.切换当前默认的shell

  chsh -s /bin/zsh
  有的平台上面的命令有问题,可以试一下下面的这一个
  command -v zsh | sudo tee -a /etc/shells
  /usr/bin/zsh
  • 1
  • 2
  • 3
  • 4

安装Oh-my-zsh

  1. 下载最新版本的oh-my-zsh
    下载地址 https://github.com/robbyrussell/oh-my-zsh
    手动将zip包下载下来。
  2. 在主目录下新建目录
 mkdir .oh-my-zsh
  • 1
  1. 解压下载下来的oh-my-zsh-master.zip到.oh-my-zsh下面
    注意是压缩包里面的东西,不要.oh-my-zsh里面又包了一个oh-my-zsh文件夹
  2. 拷贝文件
 cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
  • 1

以后所有修改配置文件,都是在.zshrc文件里面修改即可。

最后,需要source ~/.zshrc将配置生效。以下修改了.zshrc文件之后,都执行一下这个命令

zsh主题

通过如下命令可以查看可用的Theme:

ls ~/.oh-my-zsh/themes
  • 1

如何修改zsh主题呢?
编辑~/.zshrc文件,将ZSH_THEME=“candy”,即将主题修改为candy。我采用的ys。

插件安装方法

安装对应的插件

sudo apt-get install  extract
  • 1

在~/.zshrc中找到plugins关键字,就可以自定义启用的插件了,系统默认加载git。
打开文件~/.zshrc,其中有如下行:
plugins=(git)

将需要的插件按空格分开,放于此处即可。我的配置如下(这是4个插件)
plugins=(git extract z sublime)

  1. extract

解压文件用的,所有的压缩文件,都可以直接x filename,不用记忆参数
当然,如果你想要用tar命令,可以使用tar -加tab键,zsh会列出参数的含义

  1. z

强大的目录自动跳转命令,会记忆你曾经进入过的目录,用模糊匹配快速进入你想要的目录
z -stat:可以查看历史路径库 历史访问记录放在 .z 文件里

  1. git插件

命令内容可以参考cat ~/.oh-my-zsh/plugins/git/git.plugin.zsh。
zsh-autosuggestion 插件
手动下载解压,注意修改文件夹的名字放到
/home/jiahao/.oh-my-zsh/custom/plugins/ 目录下 不要zsh-autosuggestion目录套zsh-autosuggestion目录
source ~/.zshrc

  1. zsh-syntax-highlighting 插件

clone项目到文件夹下 (默认为 ~/.oh-my-zsh/custom/plugins)

cd ~/.oh-my-zsh/custom/plugins
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
  • 1
  • 2

常见错误

autoload: command not found
bash: /home/hyh/.oh-my-zsh/oh-my-zsh.sh: line 34: syntax error near unexpected token `('
bash: /home/hyh/.oh-my-zsh/oh-my-zsh.sh: line 34: `for config_file ($ZSH/lib/*.zsh); do'
  • 1
  • 2
  • 3

解决方法:
在终端上直接输入 zsh
一切正常。
但是 不会让我每次打开一个终端,都要我输入一次zsh吧?
我直接把 zsh 追加到HOME/.bashrc 最后面
这样每次打开终端就会帮我自动输入一次zsh命令

但是这种方式慎用,可能会导致scp的时候卡住,别的机器不能往你这台机器上scp文件

rm -rf .zcompdump
rm -rf .zcompdump-ubuntu-5.1.1
  • 1
  • 2

我的 .zshrc 文件配置

在我的zshrc文件中使用alias来简化一些常用的命令,来提升效率,如:

alias ff="find . -name"
alias gg='grep -rn'
  • 1
  • 2

简化经常使用的查找文件以及查找某些字符

alias yoc='cd /home/xx/xx'
  • 1

简化自己经常访问的开发目录

alias mkcscopefile='find `pwd` -name "*.[ch]" -o -name "*.cpp" > cscope.files'
alias mktag='ctags -R;cscope -bR'
  • 1
  • 2

简化cscope命令,来建立代码中函数以及变量等的链接

# 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/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="ys"

# 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"

setopt no_nomatch
CSCOPE_DB=/home/jiahao/hongmeng//hm-verif-kernel/cscope.out
export CSCOPE_DB

# 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 ~/.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=(
 gitfast
 z
 extract
 sublime
 zsh-syntax-highlighting
)

source $ZSH/oh-my-zsh.sh
source ~/.profile
# 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"
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
  OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
  zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}

pastefinish() {
  zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish

alias ff="find . -name"
alias gg='grep -rn'
alias yoc='cd /home/xx/xx'
alias jj='z'
alias mkcscopefile='find `pwd` -name "*.[ch]" -o -name "*.cpp" -o -name "*.hpp" > cscope.files'
alias mktag='ctags -R;cscope -bR'

export PATH=$HOME/install/qemu:$PATH
export PATH=$HOME/install/SDK/sysroots/x86_64-eulersdk-linux/usr/bin:$PATH
export PATH=$HOME/install/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin:$PATH

[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
  • 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

有的时候会感觉安装zsh以后,使用git 命令在用tab补全的时候很慢,可以加一下gitfast这个插件试一下

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/825213
推荐阅读
相关标签
  

闽ICP备14008679号