create a zsh prompt command containing the following items in order.
The color of each item is listed before the item in parens.
(blue) user name
(purple) host name
(yellow) current working directory
(black) active git branch
(green) checkmark if my git repository is clean
(red) XXX if my git repository is dirty
(red) current Ruby version number
Created
June 27, 2025 19:39
-
-
Save jswright61/69a039e122fb1f184e04f58b460176ab to your computer and use it in GitHub Desktop.
Zsh prompt from Claude
please add a right prompt on line 2 that displays the elapsed time in seconds of the last executed command
the code '$(date +%s%0N)/1000000)' throws an exception
This file contains hidden or 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
| # Add this to your ~/.zshrc file | |
| # Enable prompt substitution | |
| setopt PROMPT_SUBST | |
| # Function to get git branch | |
| git_branch() { | |
| git branch 2>/dev/null | grep '^*' | sed 's/* //' | |
| } | |
| # Function to check git status | |
| git_status() { | |
| if git rev-parse --git-dir > /dev/null 2>&1; then | |
| if [[ -z $(git status --porcelain) ]]; then | |
| echo "%F{green}✓%f" | |
| else | |
| echo "%F{red}XXX%f" | |
| fi | |
| fi | |
| } | |
| # Function to get Ruby version | |
| ruby_version() { | |
| if command -v ruby > /dev/null 2>&1; then | |
| ruby -v | awk '{print $2}' | |
| fi | |
| } | |
| # Function to calculate command execution time | |
| preexec() { | |
| timer=$(date +%s) | |
| } | |
| precmd() { | |
| if [ $timer ]; then | |
| now=$(date +%s) | |
| elapsed=$(($now-$timer)) | |
| unset timer | |
| fi | |
| } | |
| # Set the prompt | |
| PROMPT='%F{blue}%n%f@%F{magenta}%m%f:%F{yellow}%~%f%F{black}$(git_branch)%f$(git_status) %F{red}$(ruby_version)%f | |
| $ ' | |
| # Set the right prompt with elapsed time | |
| RPROMPT='%F{cyan}${elapsed:+${elapsed}s}%f' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment