欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ubuntu安装ohmyzsh

程序员文章站 2022-05-26 19:01:21
...

安装git和zsh

sudo apt-get install git zsh

安装ohmyzsh

官方安装说明,官方给的命令本质上为下载源代码至~/.oh-my-zh目录。

因为github连接常常发生中断,以下使用hub.fastgit.org镜像站进行下载安装,也可直接下载ZIP文件。

(base)
# sky @ DESKTOP-NJJGMD8 in ~/github [19:04:15]
$ git clone https://hub.fastgit.org/ohmyzsh/ohmyzsh.git
Cloning into 'ohmyzsh'...
remote: Enumerating objects: 26382, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 26382 (delta 3), reused 8 (delta 1), pack-reused 26369
Receiving objects: 100% (26382/26382), 7.70 MiB | 800.00 KiB/s, done.
Resolving deltas: 100% (13229/13229), done.

安装常用的插件(可跳过)

https://github.com/zsh-users

本质为下载插件源代码至ohmyzsh/pluginsohmyzsh/custom/plugins目录

此处分别下载zsh-autosuggestionszsh-syntax-highlighting

(base)
# sky @ DESKTOP-NJJGMD8 in ~/github on git:master o [19:06:42]
$ cd ohmyzsh/custom/plugins
(base)
# sky @ DESKTOP-NJJGMD8 in ~/github/ohmyzsh/custom/plugins on git:master o [19:09:06]
$ ls
example
(base)
# sky @ DESKTOP-NJJGMD8 in ~/github/ohmyzsh/custom/plugins on git:master o [19:09:06]
$ git clone https://hub.fastgit.org/zsh-users/zsh-autosuggestions.git
Cloning into 'zsh-autosuggestions'...
remote: Enumerating objects: 2435, done.
remote: Counting objects: 100% (50/50), done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 2435 (delta 21), reused 22 (delta 9), pack-reused 2385
Receiving objects: 100% (2435/2435), 566.34 KiB | 276.00 KiB/s, done.
Resolving deltas: 100% (1552/1552), done.
(base)
# sky @ DESKTOP-NJJGMD8 in ~/github/ohmyzsh/custom/plugins on git:master o [19:10:45] C:130
$ git clone https://hub.fastgit.org/zsh-users/zsh-syntax-highlighting.git
Cloning into 'zsh-syntax-highlighting'...
remote: Enumerating objects: 6943, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 6943 (delta 10), reused 20 (delta 5), pack-reused 6913
Receiving objects: 100% (6943/6943), 1.49 MiB | 98.00 KiB/s, done.
Resolving deltas: 100% (4685/4685), done.
(base)
# sky @ DESKTOP-NJJGMD8 in ~/github/ohmyzsh/custom/plugins on git:master o [19:11:56]
$ ls
example  zsh-autosuggestions  zsh-syntax-highlighting

修改.zshrc文件

拷贝模板文件至~/.zshrc

# sky @ DESKTOP-NJJGMD8 in ~/github/ohmyzsh on git:master o [19:47:25]
$ cp templates/zshrc.zsh-template ~/.zshrc

修改~/.zshrc文件

  • ZSH对应的路径:export ZSH=/home/sky/github/ohmyzsh

  • 添加插件(可跳过):plugins=(git z zsh-autosuggestions zsh-syntax-highlighting)

其中zsh-syntax-highlighting需执行以下命令在.zshrc的末尾添加**命令

# sky @ DESKTOP-NJJGMD8 in ~/github/ohmyzsh/custom/plugins on git:master o [20:21:59]
$ echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc

~/.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
export ZSH=/home/sky/github/ohmyzsh

# 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 $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 z zsh-autosuggestions zsh-syntax-highlighting)

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"

source /home/sky/github/ohmyzsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

**zsh

(base) [email protected]:/mnt/c/Users/strive$ echo $SHELL
/bin/bash
(base) [email protected]:/mnt/c/Users/strive$ zsh
(base)
# sky @ DESKTOP-NJJGMD8 in /mnt/c/Users/strive [19:53:47]
$ source ~/.zshrc
(base)
# sky @ DESKTOP-NJJGMD8 in /mnt/c/Users/strive [19:53:51]
$

修改默认shell

(base)
# sky @ DESKTOP-NJJGMD8 in /mnt/c/Users/strive [19:56:07]
$ cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/usr/bin/tmux
/usr/bin/screen
/bin/zsh
/usr/bin/zsh
(base)
# sky @ DESKTOP-NJJGMD8 in /mnt/c/Users/strive [19:54:21]
$ chsh -s /bin/zsh
Password:
(base)
# sky @ DESKTOP-NJJGMD8 in /mnt/c/Users/strive [19:55:19]
$
相关标签: Ubuntu