git/list[1] front-page[2] threads[3] people[4] search[5] about
 

current HEAD in bash prompt

From
Ben Clifford <benc@hawaga.org.uk>
Date
Nov 17, 2005, 08:39 UTC
Message-ID
<9C44605A-4F0F-42FA-A8ED-A4F7EFA24C32@hawaga.org.uk>

After getting a bit confused when having too many branches, and for people who don't mind extra forks and like too much info in their prompt, I've recently started using this:

export PS1='!\! [\j] \u@\h:\w$(output-git-head-or-blank)\$ '
where output-git-head-or-blank is:
#!/bin/bash

PS_GIT=$(git-symbolic-ref HEAD 2>/dev/null) && echo "[$(basename $PS_GIT)]" && exit

# else output nothing

When in a non-git directory, you get a non-git prompt (of course, modify this to whatever you want)

!502 [0] benc@piva:~$

and when in a git directory you get (a truncated form of) whatever today's head points at:

!502 [0] benc@piva:~$ cd src/globe !503 [0] benc@piva:~/src/globe[master]$

-- 
Ben • ベン • Бэн • 벤 • 班明
http://www.hawaga.org.uk/ben/
My email is high latency but best way to contact me. Alternatively,  
SMS number(s) at above URL.
Next: Alex Riesen
Message 1 of 2 in “current HEAD in bash prompt”
  1. Ben CliffordNov 17, 2005
  2. Alex RiesenNov 18, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.