TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

My Extravagant Zsh Prompt

65 pointsby thmzltabout 14 years ago

7 comments

JoshTriplettabout 14 years ago
I took the minimal approach with my prompt. Under normal circumstances, my prompt looks like this:<p><pre><code> ~$ </code></pre> I only show the username and hostname in my prompt if remote or unusual: [ -n "$SSH_CONNECTION" ] || [ "$USER" != "josh" ]. If either of those, I prefix my prompt with "user@host:". Apart from that, I show the exit status of the last command run, if non-zero. In general, I try to hide all boring information and show useful information only.
grayrestabout 14 years ago
If anybody's interested, here's my considerably less extravagant Zsh prompt[1]. It shows the current directory along with what top level directory you're in on the right prompt along with VCS info. The left side shows backgrounded jobs marked with pipes but otherwise is just a $ so command lines wrap less frequently. It uses the vcs_info functionality from zshkit[2].<p>[1] <a href="http://gr.ayre.st/s/screenshots/git/git_working.png" rel="nofollow">http://gr.ayre.st/s/screenshots/git/git_working.png</a> [2] <a href="https://github.com/mattfoster/zshkit" rel="nofollow">https://github.com/mattfoster/zshkit</a><p><pre><code> function prompt_grayrest_setup { unset PS1 PS2 PS3 PS4 PROMPT RPROMPT autoload colors zsh/terminfo if [[ "$terminfo[colors]" -ge 8 ]]; then colors fi # Colours accepted as arguments local u_col=${1:-'green'} local h_col=${2:-'blue'} local d_col=${3:-'yellow'} local d_col_pre='blue' local job_color='yellow' local n_tru=${4:-'blue'} local n_fal=${5:-'yellow'} # looks like: ee1mpf@eepc-tsar16 ~ $ ps1=( # "%{$fg_bold[$u_col]%}%n@" # "%{$fg_bold[$h_col]%}%m " "%1(j.%{$fg_bold[$job_color]%}.)" "%4(j.%{$reset_color$fg[$job_color]%}[%{$reset_color$fg_bold[$job_color]%}%j%{$reset_color$fg[$job_color]%}] .%3(j.||| .%2(j.|| .%1(j.| .))))" "%{$reset_color%}" "%{%(?.$fg[$n_tru].$fg[$n_fal])%}$ " "%{$reset_color%}" ) ps2=( "%_ %{$fg[$d_col]%}-&#62; " "%{$reset_color%}" ) rps1=( '%{$fg[$b_col]%}${vcs_info_msg_0_}%{$reset_color%}' " %{$fg[$d_col]%}%(4~.%{$fg[$d_col_pre]%}%-1~%{$fg[$d_col]%} %2~.%3~) %{$reset_color%}" ) PS2="${(j::)ps2}" PS1="${(j::)ps1}" RPS1="${(j::)rps1}" }</code></pre>
评论 #2343337 未加载
freedrullabout 14 years ago
Why oh why do you need your battery life displayed in your prompt? There are plenty of other places to display it.
评论 #2342928 未加载
评论 #2343060 未加载
评论 #2343779 未加载
评论 #2342829 未加载
评论 #2343006 未加载
flexdabout 14 years ago
I just use oh-my-zsh (<a href="https://github.com/robbyrussell/oh-my-zsh" rel="nofollow">https://github.com/robbyrussell/oh-my-zsh</a>) to quickly enable half these things.<p>➜ civ5replays git:(master) ✗<p>Looks like that now, the X means uncommited changes. civ5replays being the folder, the rest being... the rest!
metabrewabout 14 years ago
My favourite prompt-hack is to colourise the $ when the previous command exits non-zero, here's how I have my bash PS1 set up: <a href="http://www.metabrew.com/article/updated-bash-ps1" rel="nofollow">http://www.metabrew.com/article/updated-bash-ps1</a><p>If you exit `top` by pressing q, it exits with non-zero - who knew? :)
yogsotothabout 14 years ago
May I suggest to use this prompt for git users[1]. I use it daily and I am really happy with it.<p>[1]: <a href="http://sebastiancelis.com/2009/11/16/zsh-prompt-git-users/" rel="nofollow">http://sebastiancelis.com/2009/11/16/zsh-prompt-git-users/</a>
honzaabout 14 years ago
I love how Steve's articles get rediscovered and resubmitted over and over.