Archlnux 打造极速 Shell 终端 zsh+zim

环境

Arch Linux + KDE Plasma

安装 zsh

1
yay -S zsh

更改默认终端

1
chsh -s /bin/zsh

zimfw

https://zimfw.sh/docs/

安装 zimfw 需要在 git 下载建议在终端使用代理

1
2
export http_proxy="127.0.0.1:7890"
export https_proxy="127.0.0.1:7890"

With curl:

1
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh

With wget:

1
wget -nv -O - https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh

重启后即可进入 zim

如果安装 zim 成功,模块安装失败则重新安装模块:

1
zimfw install

配置

zsh 配置

vim ~/.zshrc

1
2
3
4
5
6
7
8
# 命令可以使用匹配符,例:(find / -name auto*)
setopt no_nomatch

# 命令别名
alias pc="proxychains4"
alias la="ls -a"
alias lh="ll -h"
alias docker="sudo docker"

degit

将 degit 设置为默认工具

1
zstyle ':zim:zmodule' use 'degit'

主题

默认主题:https://zimfw.sh/docs/themes/

1
vim 
  1. 主题名称为你喜欢的主题
    1
    2
    3
    4
    5
    6
    # 找到默认主题并修改为你自己喜欢的主题
    # zmodule asciiship
    zmodule magicmace

    # 依赖:获取工作目录
    zmodule prompt-pwd
  2. 执行安装
    1
    zimfw install

模块

autojump

1
yay -S autojump

vim ~/.zshrc 添加以下内容

1
[[ -s /etc/profile.d/autojump.sh ]] && . /etc/profile.d/autojump.sh

自定义模块

sudo

双击 esc 在命令前加上 sudo
https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/sudo/sudo.plugin.zsh

1
2
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/7dcabbe6826073ef6069c8a4b6f9a943f00d2df0/plugins/sudo/sudo.plugin.zsh -O ~/.zim/modules/sudo/sudo.zsh
chmod +x ~/.zim/modules/sudo/sudo.zsh

添加到 ~/.zimrc

1
zmodule sudo

root 用户共享配置

1
2
3
sudo ln -s /home/likfees/.zim /root/.zim
sudo ln -s /home/likfees/.zimrc /root/.zimrc
sudo ln -s /home/likfees/.zshrc /root/.zshrc

image-20220115223114689

命令行回收站

1
yay -S trash-cli

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Start configuration added by Zim install {{{
#
# User configuration sourced by interactive shells
#

# -----------------
# Zsh configuration
# -----------------

#
# History
#

# Remove older command from the history if a duplicate is to be added.
setopt HIST_IGNORE_ALL_DUPS

#
# Input/output
#

# Set editor default keymap to emacs (`-e`) or vi (`-v`)
bindkey -e

# Prompt for spelling correction of commands.
#setopt CORRECT

# Customize spelling correction prompt.
#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '

# Remove path separator from WORDCHARS.
WORDCHARS=${WORDCHARS//[\/]}

# -----------------
# Zim configuration
# -----------------

# Use degit instead of git as the default tool to install and update modules.
#zstyle ':zim:zmodule' use 'degit'

# --------------------
# Module configuration
# --------------------

#
# git
#

# Set a custom prefix for the generated aliases. The default prefix is 'G'.
#zstyle ':zim:git' aliases-prefix 'g'

#
# input
#

# Append `../` to your input for each `.` you type after an initial `..`
#zstyle ':zim:input' double-dot-expand yes

#
# termtitle
#

# Set a custom terminal title format using prompt expansion escape sequences.
# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes
# If none is provided, the default '%n@%m: %~' is used.
#zstyle ':zim:termtitle' format '%1~'

#
# zsh-autosuggestions
#

# Disable automatic widget re-binding on each precmd. This can be set when
# zsh-users/zsh-autosuggestions is the last module in your ~/.zimrc.
ZSH_AUTOSUGGEST_MANUAL_REBIND=1

# Customize the style that the suggestions are shown with.
# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style
#ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=242'

#
# zsh-syntax-highlighting
#

# Set what highlighters will be used.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets)

# Customize the main highlighter styles.
# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it
#typeset -A ZSH_HIGHLIGHT_STYLES
#ZSH_HIGHLIGHT_STYLES[comment]='fg=242'

# ------------------
# Initialize modules
# ------------------

ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim
# Download zimfw plugin manager if missing.
if [[ ! -e ${ZIM_HOME}/zimfw.zsh ]]; then
if (( ${+commands[curl]} )); then
curl -fsSL --create-dirs -o ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
else
mkdir -p ${ZIM_HOME} && wget -nv -O ${ZIM_HOME}/zimfw.zsh \
https://github.com/zimfw/zimfw/releases/latest/download/zimfw.zsh
fi
fi
# Install missing modules, and update ${ZIM_HOME}/init.zsh if missing or outdated.
if [[ ! ${ZIM_HOME}/init.zsh -nt ${ZDOTDIR:-${HOME}}/.zimrc ]]; then
source ${ZIM_HOME}/zimfw.zsh init -q
fi
# Initialize modules.
source ${ZIM_HOME}/init.zsh

# ------------------------------
# Post-init module configuration
# ------------------------------

#
# zsh-history-substring-search
#

zmodload -F zsh/terminfo +p:terminfo
# Bind ^[[A/^[[B manually so up/down works both before and after zle-line-init
for key ('^[[A' '^P' ${terminfo[kcuu1]}) bindkey ${key} history-substring-search-up
for key ('^[[B' '^N' ${terminfo[kcud1]}) bindkey ${key} history-substring-search-down
for key ('k') bindkey -M vicmd ${key} history-substring-search-up
for key ('j') bindkey -M vicmd ${key} history-substring-search-down
unset key
# }}} End configuration added by Zim install

[[ -s /etc/profile.d/autojump.sh ]] && . /etc/profile.d/autojump.sh

source /etc/profile

setopt no_nomatch

# 命令别名
alias pc="proxychains4"
alias la="ls -a "
alias lla="ll -a "
alias llah="ll -ha "
alias docker="sudo docker "
alias vim="sudo nvim "
alias vi="sudo nvim "
alias v="sudo nvim "
alias sudo="sudo "
alias axel="axel -n 10 "
alias runlike="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock assaflavie/runlike"
alias findall="sudo find / \( -path "/run" -o -path "/proc" -o -path "/data" -o -path "/tmp" -o -path "~/.local/share/icons" -o -path "/usr/share/icons" \) -prune -o -name"
alias gitc="git clone"
alias systemctl="sudo systemctl"
alias "cd.."="cd .."
alias yayq="yay -Q | grep "
alias zshrc="vim ~/.zshrc"
alias rm="trash-put"