summaryrefslogtreecommitdiff
path: root/dot_config/zsh/functions
diff options
context:
space:
mode:
authorChloƩ Vulquin <code@toast.bunkerlabs.net>2026-01-19 22:51:02 +0100
committerChloƩ Vulquin <code@toast.bunkerlabs.net>2026-01-23 00:04:34 +0100
commit3e9cb0137162fe9ca2230ae8a26b717eb419d58a (patch)
treece2a2dd8507b0e2731d3e8cb1ab3d8f0e7416fb3 /dot_config/zsh/functions
parentxbps: check packages by default (diff)
zsh: add zstyle prompt
aka the prompt to rule them all
Diffstat (limited to 'dot_config/zsh/functions')
-rw-r--r--dot_config/zsh/functions/prompt_zstyle_setup92
1 files changed, 92 insertions, 0 deletions
diff --git a/dot_config/zsh/functions/prompt_zstyle_setup b/dot_config/zsh/functions/prompt_zstyle_setup
new file mode 100644
index 0000000..256464c
--- /dev/null
+++ b/dot_config/zsh/functions/prompt_zstyle_setup
@@ -0,0 +1,92 @@
+# vim: ft=zsh
+# a prompt entirely configured by zstyle, usable by default
+# make sure you configure vcs_info!
+
+prompt_opts=(subst percent)
+
+# default parts
+zstyle :prompt:zstyle:default:parts login '%n@%m'
+zstyle :prompt:zstyle:default:parts vcsinfo '${vcs_info_msg_0_}'
+zstyle :prompt:zstyle:default:parts return '%?'
+zstyle :prompt:zstyle:default:parts separator '%#'
+zstyle :prompt:zstyle:default:parts pwd '%~'
+
+# default prompts
+zstyle :prompt:zstyle:default ps1 \
+ login ' ' pwd ' ' vcsinfo ' ' return ' ' separator ' '
+
+prompt_zstyle_reset() {
+ zstyle -d :prompt:zstyle
+ zstyle -d :prompt:zstyle:parts
+}
+
+prompt_zstyle_doparts() {
+ # $1 is the style to query
+ local out=''
+ local part parts value
+ zstyle -a :prompt:zstyle $1 parts ||
+ zstyle -a :prompt:zstyle:default $1 parts ||
+ parts=()
+ for part in $parts; do
+ zstyle -s :prompt:zstyle:parts $part value ||
+ zstyle -s :prompt:zstyle:default:parts $part value ||
+ value=$part
+ print -n "$value"
+ done
+}
+autoload -Uz vcs_info
+prompt_zstyle_precmd() {
+ vcs_info
+
+ PS1=$(prompt_zstyle_doparts ps1)
+ PS2=$(prompt_zstyle_doparts ps2)
+ PS3=$(prompt_zstyle_doparts ps3)
+ PS4=$(prompt_zstyle_doparts ps4)
+ RPS1=$(prompt_zstyle_doparts rps1)
+ RPS2=$(prompt_zstyle_doparts rps2)
+}
+autoload -Uz add-zsh-hook
+add-zsh-hook precmd prompt_zstyle_precmd
+
+# presets
+prompt_zstyle_preset() {
+ case $1 in
+ fish)
+ prompt_zstyle_reset
+ zstyle :prompt:zstyle:parts login '%(!.%F{red}.%F{green})%n%f@%m'
+ zstyle :prompt:zstyle:parts return '%(0?.. %F{red}[%?]%f)'
+ zstyle :prompt:zstyle:parts separator '%(!.#.>)'
+ zstyle :prompt:zstyle:parts vcsinfo \
+ '${vcs_info_msg_0_:+ $vcs_info_msg_0_}'
+ zstyle :prompt:zstyle ps1 \
+ login ' ' pwd vcsinfo return separator ' '
+ ;;
+ esac
+}
+
+prompt_zstyle_help() {
+ cat <<-EOF
+ Entirely zstyle-configured prompt.
+
+ :prompt:zstyle {ps{1,2,3,4},rps{1,2}} is used as the specification,
+ each part of those arrays is either found in :prompt:zstyle:parts or
+ :prompt:zstyle:default:parts, or it's set as is. This means you can
+ put bare strings in there, like ' ' or '%~', and customize various parts
+ by setting them under :prompt:zstyle:parts.
+
+ If you enable this prompt with a preset, it will set some styles for you
+ in accordance with the preset. Available presets are:
+ * fish (like the fish shell)
+
+ To completely reset user customizations (except stuff under :defaults),
+ run prompt_zstyle_reset.
+
+ Note that it's up to you to configure vcs_info.
+ The default vcsinfo part simply prints ${vcs_info_msg_0_}.
+ Some presets will prepend it with a space (if non-null only).
+
+ Promptsubst is enabled, so you can have function calls in your custom parts.
+ EOF
+}
+
+(( $# )) && prompt_zstyle_preset "$@"