Last active
April 25, 2025 15:47
-
-
Save phakeandy/90ed859d6bccb4d634f317110e965daa to your computer and use it in GitHub Desktop.
Simple zshrc with less plugins, Modified from kali linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NEED install zsh-autosuggestions and zsh-syntax-highlighting | |
# `sudo apt install zsh-syntax-highlighting zsh-autosuggestions` | |
setopt autocd # change directory just by typing its name | |
#setopt correct # auto correct mistakes | |
setopt interactivecomments # allow comments in interactive mode | |
setopt magicequalsubst # enable filename expansion for arguments of the form ‘anything=expression’ | |
setopt nonomatch # hide error message if there is no match for the pattern | |
setopt notify # report the status of background jobs immediately | |
setopt numericglobsort # sort filenames numerically when it makes sense | |
setopt promptsubst # enable command substitution in prompt | |
WORDCHARS=${WORDCHARS//\/} # Don't consider certain characters part of the word | |
# hide EOL sign ('%') | |
PROMPT_EOL_MARK="" | |
# configure key keybindings | |
bindkey -e # emacs key bindings | |
bindkey ' ' magic-space # do history expansion on space | |
bindkey '^U' backward-kill-line # ctrl + U | |
bindkey '^[[3;5~' kill-word # ctrl + Supr | |
bindkey '^[[3~' delete-char # delete | |
bindkey '^[[1;5C' forward-word # ctrl + -> | |
bindkey '^[[1;5D' backward-word # ctrl + <- | |
bindkey '^[[5~' beginning-of-buffer-or-history # page up | |
bindkey '^[[6~' end-of-buffer-or-history # page down | |
bindkey '^[[H' beginning-of-line # home | |
bindkey '^[[F' end-of-line # end | |
bindkey '^[[Z' undo # shift + tab undo last action | |
# enable completion features | |
autoload -Uz compinit | |
compinit -d ~/.cache/zcompdump | |
zstyle ':completion:*:*:*:*:*' menu select | |
zstyle ':completion:*' auto-description 'specify: %d' | |
zstyle ':completion:*' completer _expand _complete | |
zstyle ':completion:*' format 'Completing %d' | |
zstyle ':completion:*' group-name '' | |
zstyle ':completion:*' list-colors '' | |
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s | |
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' | |
zstyle ':completion:*' rehash true | |
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s | |
zstyle ':completion:*' use-compctl false | |
zstyle ':completion:*' verbose true | |
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' | |
# If this is an xterm set the title to user@host:dir | |
case "$TERM" in | |
xterm*|rxvt*|Eterm|aterm|kterm|gnome*|alacritty) | |
TERM_TITLE=$'\e]0;${debian_chroot:+($debian_chroot)}${VIRTUAL_ENV:+($(basename $VIRTUAL_ENV))}%n@%m: %~\a' | |
;; | |
*) | |
;; | |
esac | |
# 启用语法高亮 | |
if [ -f /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then | |
. /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh | |
fi | |
precmd() { | |
# Print the previously configured title | |
print -Pnr -- "$TERM_TITLE" | |
# Print a new line before the prompt, but only if it is not the first line | |
if [ "$NEWLINE_BEFORE_PROMPT" = yes ]; then | |
if [ -z "$_NEW_LINE_BEFORE_PROMPT" ]; then | |
_NEW_LINE_BEFORE_PROMPT=1 | |
else | |
print "" | |
fi | |
fi | |
} | |
# enable color support of ls, less and man, and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" | |
export LS_COLORS="$LS_COLORS:ow=30;44:" # fix ls color for folders with 777 permissions | |
alias ls='ls --color=auto' | |
#alias dir='dir --color=auto' | |
#alias vdir='vdir --color=auto' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
alias diff='diff --color=auto' | |
alias ip='ip --color=auto' | |
export LESS_TERMCAP_mb=$'\E[1;31m' # begin blink | |
export LESS_TERMCAP_md=$'\E[1;36m' # begin bold | |
export LESS_TERMCAP_me=$'\E[0m' # reset bold/blink | |
export LESS_TERMCAP_so=$'\E[01;33m' # begin reverse video | |
export LESS_TERMCAP_se=$'\E[0m' # reset reverse video | |
export LESS_TERMCAP_us=$'\E[1;32m' # begin underline | |
export LESS_TERMCAP_ue=$'\E[0m' # reset underline | |
# Take advantage of $LS_COLORS for completion as well | |
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" | |
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' | |
fi | |
# some more ls aliases | |
alias ll='ls -l' | |
alias la='ls -A' | |
alias l='ls -CF' | |
# enable auto-suggestions based on the history | |
if [ -f /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh ]; then | |
. /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh | |
# change suggestion color | |
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#999' | |
fi | |
# enable command-not-found if installed | |
if [ -f /etc/zsh_command_not_found ]; then | |
. /etc/zsh_command_not_found | |
fi | |
n _fish_collapsed_pwd() { | |
local pwd="$1" | |
local home="$HOME" | |
local size=${#home} | |
[[ $# == 0 ]] && pwd="$PWD" | |
[[ -z "$pwd" ]] && return | |
if [[ "$pwd" == "/" ]]; then | |
echo "/" | |
return | |
elif [[ "$pwd" == "$home" ]]; then | |
echo "~" | |
return | |
fi | |
[[ "$pwd" == "$home/"* ]] && pwd="~${pwd:$size}" | |
if [[ -n "$BASH_VERSION" ]]; then | |
local IFS="/" | |
local elements=($pwd) | |
local length=${#elements[@]} | |
for ((i=0;i<length-1;i++)); do | |
local elem=${elements[$i]} | |
if [[ ${#elem} -gt 1 ]]; then | |
elements[$i]=${elem:0:1} | |
fi | |
done | |
else | |
local elements=("${(s:/:)pwd}") | |
local length=${#elements} | |
for i in {1..$((length-1))}; do | |
local elem=${elements[$i]} | |
if [[ ${#elem} > 1 ]]; then | |
elements[$i]=${elem[1]} | |
fi | |
done | |
fi | |
local IFS="/" | |
echo "${elements[*]}" | |
} | |
if [ -n "$BASH_VERSION" ]; then | |
if [ "$UID" -eq 0 ]; then | |
export PS1='\u@\h \[\e[31m\]$(_fish_collapsed_pwd)\[\e[0m\]# ' | |
else | |
export PS1='\u@\h \[\e[32m\]$(_fish_collapsed_pwd)\[\e[0m\]> ' | |
fi | |
else | |
if [ $UID -eq 0 ]; then | |
export PROMPT='%(1j.*.)%f%n@%m %F{1}$(_fish_collapsed_pwd)%f # ' | |
else | |
export PROMPT='%(1j.*.)%f%n@%m %F{2}$(_fish_collapsed_pwd)%f $ ' | |
fi | |
fi | |
if [ -f /etc/environment ]; then | |
source /etc/environment | |
fi | |
if [ -f $HOME/.local/config/shell/main.sh ]; then | |
source $HOME/.local/config/shell/main.sh | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment