Skip to content

Instantly share code, notes, and snippets.

@khursani8
Last active September 20, 2025 08:34
Show Gist options
  • Select an option

  • Save khursani8/5a025e9851b99f3ce8f331a147bbdc13 to your computer and use it in GitHub Desktop.

Select an option

Save khursani8/5a025e9851b99f3ce8f331a147bbdc13 to your computer and use it in GitHub Desktop.
# >>> MY_CUSTOM_ZSH >>>
# Enable dynamic prompt substitution
setopt PROMPT_SUBST
# Track elapsed time
preexec() {
timer=$(date +%s%3N)
}
precmd() {
if [ -n "$timer" ]; then
now=$(date +%s%3N)
elapsed=$(( (now - timer)/1000 )) # elapsed in seconds
if [ $elapsed -ge 1 ]; then
if [ $elapsed -ge 60 ]; then
mins=$(( elapsed / 60 ))
secs=$(( elapsed % 60 ))
CMD_DURATION=" (${mins}m${secs}s)"
else
CMD_DURATION=" (${elapsed}s)"
fi
else
CMD_DURATION=""
fi
fi
}
# Git branch helper
git_branch() {
ref=$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --exact-match 2>/dev/null)
[ -n "$ref" ] && echo "($ref)"
}
# Custom compact prompt with GMT+8 time
PROMPT='%F{cyan}$(TZ=Asia/Singapore date "+%H:%M:%S")%f %F{yellow}%~%f %F{magenta}$(git_branch)%f%F{green}${CMD_DURATION}%f
$ '
# <<< MY_CUSTOM_ZSH <<<
@khursani8
Copy link
Copy Markdown
Author

khursani8 commented Sep 20, 2025

#!/usr/bin/env bash
set -e

# Your gist raw URL (replace with your own!)
GIST_URL="https://gist.githubusercontent.com/username/<hash>/raw/zshrc_append"

# File to modify
ZSHRC="$HOME/.zshrc"

# Markers
START="# >>> MY_CUSTOM_ZSH >>>"
END="# <<< MY_CUSTOM_ZSH <<<"

echo "[*] Updating $ZSHRC from gist..."

# Remove old block if it exists
if grep -q "$START" "$ZSHRC"; then
  sed -i "/$START/,/$END/d" "$ZSHRC"
  echo "[*] Removed old custom block."
fi

# Fetch new block
block=$(curl -fsSL "$GIST_URL")

# Append new block
echo "$block" >> "$ZSHRC"
echo "[*] Added new custom block."

# Reload zsh
exec zsh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment