终端环境的个性化配置:自用的 .zshrc、neofetch、以及在国内网络下安装 oh-my-zsh。
自用的.zshrc配置文件 偶然找到的,需要配置好 zsh 和 oh-my-zsh 方可使用。
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 autoload colorscolors for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do eval _$color ='%{$terminfo[bold]$fg[${(L)color}]%}' eval $color ='%{$fg[${(L)color}]%}' (( count = $count + 1 )) done FINISH="%{$terminfo [sgr0]%}" RPROMPT=$(echo "$RED %D %T$FINISH " ) PROMPT=$(echo "$CYAN %n@$YELLOW %M:$GREEN %/$_YELLOW >$FINISH " ) case $TERM in (*xterm*|*rxvt*|(dt|k|E)term)precmd () { print -Pn "\e]0;%n@%M//%/\a" }preexec () { print -Pn "\e]0;%n@%M//%/\ $1 \a" };; esac export EDITOR=vimexport XMODIFIERS="@im=ibus" export QT_MODULE=ibusexport GTK_MODULE=ibusexport HISTSIZE=10000export SAVEHIST=10000export HISTFILE=~/.zhistorysetopt INC_APPEND_HISTORYsetopt HIST_IGNORE_DUPSsetopt EXTENDED_HISTORY setopt AUTO_PUSHDsetopt PUSHD_IGNORE_DUPS cd () {builtin cd "$@ " fc -W local HISTDIR="$HOME /.zsh_history$PWD " if [ ! -d "$HISTDIR " ] ; then mkdir -p "$HISTDIR " fi export HISTFILE="$HISTDIR /zhistory" touch $HISTFILE local ohistsize=$HISTSIZE HISTSIZE=0 HISTSIZE=$ohistsize fc -R } mkdir -p $HOME /.zsh_history$PWD export HISTFILE="$HOME /.zsh_history$PWD /zhistory" function allhistory { cat $(find $HOME /.zsh_history -name zhistory) }function convhistory {sort $1 | uniq |sed 's/^:\([ 0-9]*\):[0-9]*;\(.*\)/\1::::::\2/' | awk -F"::::::" '{ $1=strftime("%Y-%m-%d %T",$1) "|"; print }' } function histall { convhistory =(allhistory) |sed '/^.\{20\} *cd/i\\' } function hist { convhistory $HISTFILE } function top50 { allhistory | awk -F':[ 0-9]*:[0-9]*;' '{ $1="" ; print }' | sed 's/ /\n/g' | sed '/^$/d' | sort | uniq -c | sort -nr | head -n 50 } setopt INTERACTIVE_COMMENTS setopt AUTO_CD setopt complete_in_word limit coredumpsize 0 bindkey -e WORDCHARS='*?_-[]~=&;!#$%^(){}<>' setopt AUTO_LISTsetopt AUTO_MENU autoload -U compinitcompinit zstyle ':completion:*' verbose yes zstyle ':completion:*' menu select zstyle ':completion:*:*:default' force-list alwayszstyle ':completion:*' select-prompt '%SSelect: lines: %L matches: %M [%p]' zstyle ':completion:*:match:*' original onlyzstyle ':completion::prefix-1:*' completer _completezstyle ':completion:predict:*' completer _completezstyle ':completion:incremental:*' completer _complete _correctzstyle ':completion:*' completer _complete _prefix _correct _prefix _match _approximate zstyle ':completion:*' expand 'yes' zstyle ':completion:*' squeeze-shlashes 'yes' zstyle ':completion::complete:*' '\\' eval $(dircolors -b)export ZLSCOLORS="${LS_COLORS} " zmodload zsh/complistzstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' zstyle ':completion:*' completer _complete _match _approximatezstyle ':completion:*:match:*' original onlyzstyle ':completion:*:approximate:*' max-errors 1 numeric compdef pkill=kill compdef pkill=killall zstyle ':completion:*:*:kill:*' menu yes select zstyle ':completion:*:*:*:*:processes' force-list alwayszstyle ':completion:*:processes' command 'ps -au$USER' zstyle ':completion:*:matches' group 'yes' zstyle ':completion:*' group-name '' zstyle ':completion:*:options' description 'yes' zstyle ':completion:*:options' auto-description '%d' zstyle ':completion:*:descriptions' format $'\e[01;33m -- %d --\e[0m' zstyle ':completion:*:messages' format $'\e[01;35m -- %d --\e[0m' zstyle ':completion:*:warnings' format $'\e[01;31m -- No Matches Found --\e[0m' zstyle ':completion:*:corrections' format $'\e[01;32m -- %d (errors: %e) --\e[0m' zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'users' 'expand' zle_highlight=(region:bg =magenta special:bold isearch:underline)#搜索时使用的关键字 user-complete (){ case $BUFFER in "" ) BUFFER="cd " zle end-of-linezle expand-or-complete;; "cd --" ) BUFFER="cd +" zle end-of-linezle expand-or-complete;; "cd +-" ) BUFFER="cd -" zle end-of-linezle expand-or-complete;; * ) zle expand-or-complete;; esac } zle -N user-completebindkey "\t" user-complete sudo-command-line () { [[ -z $BUFFER ]] && zle up-history [[ $BUFFER != sudo \ * ]] && BUFFER="sudo $BUFFER " zle end-of-line } zle -N sudo-command-linebindkey "\e\e" sudo-command-line alias cp ='cp -i' alias mv ='mv -i' alias rm ='rm -i' alias ls ='ls -F --color=auto' alias ll='ls -al' alias grep='grep --color=auto' alias la='ls -a' alias pacman='sudo pacman-color' alias p='sudo pacman-color' alias y='yaourt' alias h='htop' alias vim='sudo vim' alias run-help >&/dev/null && unalias run-helpautoload run-help alias top10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10' hash -d A="/media/ayu/dearest" hash -d H="/media/data/backup/ayu" hash -d E="/etc/" hash -d D="/home/ayumi/Documents" zstyle ':completion:*:ping:*' hosts 192.168.1.{1,50,51,100,101} www.google.com arith-eval-echo () { LBUFFER="${LBUFFER} echo \$(( " RBUFFER=" ))$RBUFFER " } zle -N arith-eval-echobindkey "^[[11~" arith-eval-echo function timeconv { date -d @$1 +"%Y-%m-%d %T" } zmodload zsh/mathfuncautoload -U zsh-mime-setupzsh-mime-setup setopt EXTENDED_GLOB setopt correctallautoload compinstall setopt extended_glob TOKENS_FOLLOWED_BY_COMMANDS=('|' '||' ';' '&' '&&' 'sudo' 'do' 'time' 'strace' ) recolor-cmd () { region_highlight=() colorize=true start_pos=0 for arg in ${(z)BUFFER} ; do ((start_pos+=${#BUFFER[$start_pos+1,-1]} -${#${BUFFER[$start_pos+1,-1]## #} } )) ((end_pos=$start_pos +${#arg} )) if $colorize ; then colorize=false res=$(LC_ALL=C builtin type $arg 2>/dev/null) case $res in *'reserved word' *) style="fg=magenta,bold" ;; *'alias for' *) style="fg=cyan,bold" ;; *'shell builtin' *) style="fg=yellow,bold" ;; *'shell function' *) style='fg=green,bold' ;; *"$arg is" *) [[ $arg = 'sudo' ]] && style="fg=red,bold" || style="fg=blue,bold" ;; *) style='none,bold' ;; esac region_highlight+=("$start_pos $end_pos $style " ) fi [[ ${${TOKENS_FOLLOWED_BY_COMMANDS[(r)${arg//|/\|} ]} :+yes} = 'yes' ]] && colorize=true start_pos=$end_pos done } check-cmd-self-insert () { zle .self-insert && recolor-cmd } check-cmd-backward-delete-char () { zle .backward-delete-char && recolor-cmd } zle -N self-insert check-cmd-self-insert zle -N backward-delete-char check-cmd-backward-delete-char
neofetch常用的配置文件 效果如图:放置在~/.config/neofetch目录下,保存为config即可。
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 #!/usr/bin/env bash export LC_ALL=Cexport LANG=Cprintinfo () { info title info underline info "Model" model info "OS" distro info "Kernel" kernel info "Uptime" uptime info "Packages" packages info "Shell" shell info "Resolution" resolution info "DE" de info "WM" wm info "WM Theme" wmtheme info "Theme" theme info "Icons" icons info "Terminal" term info "Terminal Font" termfont info "CPU" cpu info "GPU" gpu info "Memory" memory info "CPU Usage" cpu_usage info "Disk" disk info "Battery" battery info "Font" font info "Song" song info "Local IP" localip info "Public IP" publicip info "Users" users info "Birthday" birthday info linebreak info cols info linebreak }
在国内安装 oh-my-zsh 安装 zsh Ubuntu 下:
macOS 下:
后面的内容两个系统通用。
安装 oh-my-zsh 1 wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
然后给 install.sh 添加权限:
然后执行 install.sh:
如果发现很慢,可以修改为 gitee:
进入编辑状态,找到以下部分:
1 2 3 4 5 ZSH=${ZSH:-~/.oh-my-zsh} REPO=${REPO:-ohmyzsh/ohmyzsh} REMOTE=${REMOTE:-https://github.com/${REPO} .git} BRANCH=${BRANCH:-master}
然后将中间两行改为:
1 2 REPO=${REPO:-mirrors/oh-my-zsh} REMOTE=${REMOTE:-https://gitee.com/${REPO} .git}
然后保存退出,重新执行即可。
版权声明:本文为 CSDN 博主「菜饼同学」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载时请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qwe641259875/article/details/107201760/