feat(zsh): write my own prompt
This commit is contained in:
@@ -0,0 +1,59 @@
|
|||||||
|
# vim: set ft=zsh:
|
||||||
|
|
||||||
|
# For help with expansion codes, see:
|
||||||
|
# - https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
|
||||||
|
# For help with parameters, see:
|
||||||
|
# - https://zsh.sourceforge.io/Doc/Release/Parameters.html
|
||||||
|
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
function prompt_warg_precmd() {
|
||||||
|
local -a _status=(${pipestatus[@]})
|
||||||
|
RPS1=""
|
||||||
|
|
||||||
|
# Status code
|
||||||
|
if [[ ${#${_status//0/}} -gt 0 ]]; then
|
||||||
|
RPS1="$RPS1 %F{red}${(j:|:)_status}%f"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Python virtualenv
|
||||||
|
if [[ -n "$VIRTUAL_ENV" ]]; then
|
||||||
|
local _venv_name _venv_parent
|
||||||
|
local _pyvenv_file="${VIRTUAL_ENV}/pyvenv.cfg"
|
||||||
|
|
||||||
|
if [[ -f "$_pyvenv_file" ]]; then
|
||||||
|
while IFS=' = ' read -r key value; do
|
||||||
|
if [[ "$key" == "prompt" ]]; then
|
||||||
|
_venv_name="$value"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done <"$_pyvenv_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
_venv_name="${_venv_name:-${VIRTUAL_ENV:t}}"
|
||||||
|
_venv_parent="${VIRTUAL_ENV:h:t}"
|
||||||
|
|
||||||
|
if [[ "$_venv_name" == "venv" || "$_venv_name" == ".venv" ]]; then
|
||||||
|
_venv_name="$_venv_parent"
|
||||||
|
fi
|
||||||
|
|
||||||
|
RPS1="$RPS1 %F{yellow}$_venv_name%f"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Timestamp
|
||||||
|
RPS1="$RPS1 %F{008}%D{%H:%M:%S}%f"
|
||||||
|
}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
function prompt_warg_setup() {
|
||||||
|
VIRTUAL_ENV_DISABLE_PROMPT=1
|
||||||
|
prompt_opts=(bang cr sp percent subst)
|
||||||
|
# PS1="%n@%m %~ $ "
|
||||||
|
PS1='%(#.%F{red}.%12F)%n@%m%f %1~ %(#.#.$) '
|
||||||
|
PS2="> "
|
||||||
|
|
||||||
|
add-zsh-hook precmd prompt_warg_precmd
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
prompt_warg_setup "$@"
|
||||||
@@ -3,4 +3,3 @@ belak/zsh-utils path:completion
|
|||||||
belak/zsh-utils path:history
|
belak/zsh-utils path:history
|
||||||
belak/zsh-utils path:utility
|
belak/zsh-utils path:utility
|
||||||
zsh-users/zsh-autosuggestions
|
zsh-users/zsh-autosuggestions
|
||||||
romkatv/powerlevel10k
|
|
||||||
|
|||||||
@@ -1,13 +1,3 @@
|
|||||||
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
|
|
||||||
# Initialization code that may require console input (password prompts, [y/n]
|
|
||||||
# confirmations, etc.) must go above this block; everything else may go below.
|
|
||||||
cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
|
|
||||||
p10k_instant_prompt="${cache_dir}/p10k-instant-prompt-${USER}.zsh"
|
|
||||||
if [[ -r $p10k_instant_prompt ]]; then
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
source "$p10k_instant_prompt"
|
|
||||||
fi
|
|
||||||
|
|
||||||
###########
|
###########
|
||||||
# Options #
|
# Options #
|
||||||
###########
|
###########
|
||||||
@@ -23,6 +13,7 @@ setopt INTERACTIVECOMMENTS
|
|||||||
# Ref: https://zsh.sourceforge.io/Doc/Release/Parameters.html
|
# Ref: https://zsh.sourceforge.io/Doc/Release/Parameters.html
|
||||||
|
|
||||||
path+=("${HOME}/.local/bin")
|
path+=("${HOME}/.local/bin")
|
||||||
|
fpath+=("${HOME}/.zsh_functions")
|
||||||
export PATH
|
export PATH
|
||||||
export MAIL="/var/spool/mail/$USER"
|
export MAIL="/var/spool/mail/$USER"
|
||||||
export MAILCHECK=60
|
export MAILCHECK=60
|
||||||
@@ -126,14 +117,16 @@ antidote load
|
|||||||
function set_terminal_title() {
|
function set_terminal_title() {
|
||||||
local title
|
local title
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
title=$(basename $(print -P "%~"))
|
title=$(basename "$(print -P "%~")")
|
||||||
else
|
else
|
||||||
title="$1"
|
title="$1"
|
||||||
fi
|
fi
|
||||||
echo -ne "\033]2;$title\033\\"
|
echo -ne "\033]2;$title\033\\"
|
||||||
}
|
}
|
||||||
|
|
||||||
function precmd() { set_terminal_title }
|
function precmd() {
|
||||||
|
set_terminal_title
|
||||||
|
}
|
||||||
# function preexec() { set_terminal_title "$1" }
|
# function preexec() { set_terminal_title "$1" }
|
||||||
|
|
||||||
function ssh_with_title() {
|
function ssh_with_title() {
|
||||||
@@ -183,4 +176,12 @@ alias ssh='ssh_with_title'
|
|||||||
##########
|
##########
|
||||||
# eval "$(starship init zsh)"
|
# eval "$(starship init zsh)"
|
||||||
|
|
||||||
source ~/.p10k.zsh
|
autoload -Uz promptinit
|
||||||
|
promptinit
|
||||||
|
prompt warg
|
||||||
|
|
||||||
|
# The next line updates PATH for the Google Cloud SDK.
|
||||||
|
if [ -f '/home/oscar/google-cloud-sdk/path.zsh.inc' ]; then . '/home/oscar/google-cloud-sdk/path.zsh.inc'; fi
|
||||||
|
|
||||||
|
# The next line enables shell command completion for gcloud.
|
||||||
|
if [ -f '/home/oscar/google-cloud-sdk/completion.zsh.inc' ]; then . '/home/oscar/google-cloud-sdk/completion.zsh.inc'; fi
|
||||||
|
|||||||
+1
-1
@@ -40,8 +40,8 @@ SYMLINKS=(
|
|||||||
".xinitrc"
|
".xinitrc"
|
||||||
".xinit-scripts"
|
".xinit-scripts"
|
||||||
".zshrc"
|
".zshrc"
|
||||||
|
".zsh_functions"
|
||||||
".zsh_plugins.txt"
|
".zsh_plugins.txt"
|
||||||
".p10k.zsh"
|
|
||||||
".gtkrc-2.0"
|
".gtkrc-2.0"
|
||||||
".config/tmux"
|
".config/tmux"
|
||||||
".config/alacritty"
|
".config/alacritty"
|
||||||
|
|||||||
Reference in New Issue
Block a user