Last active
May 24, 2022 07:46
-
-
Save SimoneCheng/50583c52a7fae21d477b2972ad77953b to your computer and use it in GitHub Desktop.
my .zshrc
This file contains 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
alias git='LANG=en_GB git' | |
# Load version control information | |
autoload -Uz vcs_info | |
precmd() { vcs_info } | |
# Format the vcs_info_msg_0_ variable | |
zstyle ':vcs_info:git:*' formats '(%b)' | |
# Set up the prompt (with git branch name) | |
setopt PROMPT_SUBST | |
PROMPT='%B%F{8}%n%b%f in %B%F{48}${PWD/#$HOME/~}%f%b %B%F{69}${vcs_info_msg_0_}%f%b $ ' | |
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh | |
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh | |
source ~/.zsh/zsh-autocomplete/zsh-autocomplete.plugin.zsh |
第二種樣式
alias git='LANG=en_GB git'
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
# Load version control information
autoload -Uz vcs_info
precmd() { vcs_info }
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:git:*' formats '%F{69}git:(%f%F{216}%b%f%F{69})%f'
# 靠右上的提示
# 因為要自己計算剩下的長度還可以怎麼用才可以對齊右邊
function prompt-length() {
emulate -L zsh
local COLUMNS=${2:-$COLUMNS}
local -i x y=$#1 m
if (( y )); then
while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do
x=y
(( y *= 2 ));
done
local xy
while (( y > x + 1 )); do
m=$(( x + (y - x) / 2 ))
typeset ${${(%):-$1%$m(l.x.y)}[-1]}=$m
done
fi
echo $x
}
# 所以滿一行中間要空白
function fill-line() {
emulate -L zsh
local left_len=$(prompt-length $1)
local right_len=$(prompt-length $2 9999)
local pad_len=$((COLUMNS - left_len - right_len - ${ZLE_RPROMPT_INDENT:-1}))
if (( pad_len < 1 )); then
# Not enough space for the right part. Drop it.
echo -E - ${1}
else
local pad=${(pl.$pad_len.. .)} # pad_len spaces
echo -E - ${1}${pad}${2}
fi
}
# Set up the prompt (with git branch name)
setopt PROMPT_SUBST
RPROMPT='%B${vcs_info_msg_0_}%b'
PROMPT='$(fill-line 🏠%B%F{33}%~%f%b %F{8}%D|%T%f)
%F{73}%n%f $ '
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source ~/.zsh/zsh-autocomplete/zsh-autocomplete.plugin.zsh
Demo:
參考文章
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used Packages