aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpmemewarenet>2025-01-15 11:42:57 +0100
committerLibravatarLarge Libravatar memdmp <memdmpmemewarenet>2025-01-15 11:42:57 +0100
commit867b49fc00d54fac0a0dd875bfbdd161083d860f (patch)
treeb0544ad249c059ffebfd538e4d33cfa15a01230b
parent5ed7a6e03b0d76177d95e01920f57688e648bd5f (diff)
downloadzuwu-867b49fc00d54fac0a0dd875bfbdd161083d860f.tar.gz
zuwu-867b49fc00d54fac0a0dd875bfbdd161083d860f.tar.bz2
zuwu-867b49fc00d54fac0a0dd875bfbdd161083d860f.tar.lz
zuwu-867b49fc00d54fac0a0dd875bfbdd161083d860f.zip

feat: env variables for loading zuwu faster

All of these are booleans, where only an empty value is false:

  • _ZUWU_HYPERFAST: Attempt to load shell as fast as possible without too many compromises
  • _ZUWU_NO_STARSHIP: Skip starship detection
  • _ZUWU_NO_PROMPT: Don't set a prompt

Additionally, we create a .zshenv for the user if it doesnt exist

-rwxr-xr-xzuwu.zsh59
1 files changed, 53 insertions, 6 deletions
diff --git a/zuwu.zsh b/zuwu.zsh
index ea67cc8..0161be7 100755
--- a/zuwu.zsh
+++ b/zuwu.zsh
@@ -15,8 +15,12 @@ export _ZUWU_INSTALLED=1;
if [[ "$_ZUWU_DEBUG" == "1" ]]; then set -ax; fi
# Completion Handling
+eval_append() {
+ <<<"$2" >> "$1"
+ eval "$2"
+}
if ! grep '# The following lines were added by compinstall' ~/.zshrc >/dev/null 2>/dev/null && ! grep 'compinit' ~/.zshrc >/dev/null 2>/dev/null; then
- <<EOF >> ~/.zshrc
+ eval_append ~/.zshrc "$(<<EOF
# Note: Do not remove the 'The following lines were...' comment!
# The following lines were added by compinstall
zstyle ':completion:*' completer _complete _ignored _approximate
@@ -32,10 +36,11 @@ compinit
# End of lines added by compinstall
EOF
+)"
fi
# History Size Determination
if ! grep 'HISTSIZE' ~/.zshrc >/dev/null 2>/dev/null; then
- <<EOF >>~/.zshrc
+ eval_append ~/.zshrc "$(<<EOF
# Lines configured by zsh-newuser-install
HISTFILE="~/.histfile"
HISTSIZE="10000"
@@ -45,6 +50,39 @@ SAVEHIST="10000"
# Overwrite histfile with zuwu implementation, using HISTDIR and HISTID - if you don't want this implementation, comment out the next line.
__sethist
EOF
+)"
+fi
+
+# ZSH Env Setup
+if ! [[ -f "$HOME/.zshenv" ]]; then
+ # we want the user to have a .zshenv file, so we create it
+ # right now we dont provide an env.zsh, however this is useful for future use.
+ eval_append "$HOME/.zshenv" "$(<<EOF
+#
+# Defines environment variables, functions and aliases to be available in your shell scripts and your prompt.
+# Things that only apply to your prompt should be put into your .zshrc instead!
+#
+# Authors:
+# memdmp <https://mem.estrogen.zone/>
+#
+
+#
+# This file was generated by zuwu. You can modify it as you please.
+# Changes will only be reverted if the file is removed.
+# We recommend, for the sake of readability, removing this generated comment when changing this file for the first time.
+#
+
+# Remove the following line if you do not want zuwu's environment.
+for d in /usr/share/zsh/plugins/zuwu /usr/local/share/zsh/plugins/zuwu "\$HOME/.local/share/zsh/plugins/zuwu"; do
+ if [[ -f "\$d/env.zsh" ]]; then
+ source "\$d/env.zsh"
+ break
+ fi
+done
+
+# Put your custom environment variables below this line.
+EOF
+)";
fi
# -
@@ -180,10 +218,10 @@ while IFS= read -r f; do
done <<< "$(_each_share_dir zsh/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh)"
# Cute Prompting
-if [[ -f ~/.config/starship.toml ]]; then
+if [[ "$_ZUWU_NO_STARSHIP-$_ZUWU_NO_PROMPT" == "-" ]] && [[ -f ~/.config/starship.toml ]] && type "starship" >/dev/null; then
eval "$(starship init zsh)"
-else
- # unsure of source of function,
+elif [[ "$_ZUWU_HYPERFAST-$_ZUWU_NO_PROMPT" == "-" ]]; then
+ # unsure of source of function
hsv2rgb() {
local h=$1
local s=$2
@@ -217,7 +255,16 @@ else
_SYS_USER_COLOUR="%F{22}$(echo -ne "\x1b[38;2;${_USER_RGB}m")"
_SYS_SYSTEM_COLOUR="%B%F{green}$(echo -ne "\x1b[38;2;${_SYS_RGB}m")"
- if [[ "$(whoami)" == "root" ]]; then
+ if [[ "$USER" == "root" ]]; then
+ _SYS_USER_COLOUR="%F{red}"
+ fi
+
+ PROMPT="$(echo -n "${_SYS_USER_COLOUR}%n%f%F{7}@%f${_SYS_SYSTEM_COLOUR}%m%f%b%F{7} in %f%B%F{27}%~%f%b\n%B%F{magenta}%(?..%F{red})❯ %f%b")"
+ RPROMPT="%B%F{magenta}%(?..%F{red})%?%f%b"
+elif [[ "$_ZUWU_NO_PROMPT" == "" ]]; then
+ _SYS_USER_COLOUR="%F{22}"
+ _SYS_SYSTEM_COLOUR="%B%F{green}"
+ if [[ "$USER" == "root" ]]; then
_SYS_USER_COLOUR="%F{red}"
fi