If your shell is ZSH and you have `setopt autocd` in your .zshrc (though I think this setting is on by default):
export PS1="%~; "
this will result in the prompt: `~; ` where the ~ will change to a path relative to home.
Why do this? Well; it means you can select and paste any line in your history: your prompt becomes part of setting the proper context and is part of the command. Just select the entire line. :D
I think a huge amount of these prompts are just fiddling with things because people think they are clever, not because they are actually useful.
My prompt for years has been:
: ▶
I add the hostname if it’s an SSH session and change ▶ to # if I’m root because those are both important contexts that should be omnipresent, but aside from that, I haven’t felt like I’m missing anything at all. The CWD is in the window / tab title bar, but I never need to look at it because the CWD is always so closely tied to what I am doing in the shell that it’s always top of mind.
Git information is extremely useful to me. I notice colleagues who don't have that tend to struggle using git on the command line and use git status nearly every other command (much as I tend to do when I'm remoting into a shell with a plain prompt).
Python venvs are useful too if you have a shell for running the program and other shells that just happen to be within that directory.
I could see the case for that if it were accurate. But every implementation I’ve seen doesn’t give you accurate Git information. It gives you the status of the repo as it was when you last ran a command. If you are working on the repo in a separate editor window, then the Git information in your prompt is usually incorrect. Incorrect information is worse than no information. Besides which, your editor normally provides this information as you are working on it. Why does outdated Git information belong in a prompt when there are more convenient places to get the correct information?
I can honestly say that has never once been a problem I have had, and I've had git information in the prompt for over 10 years.
Also how is "enter" less convenient than literally any other command that you'd still have to type and run to get up-to-date information in a command line?
> I can honestly say that has never once been a problem I have had, and I've had git information in the prompt for over 10 years.
What do you mean exactly?
Are you saying it doesn’t get out of date? i.e. you never change the state of the repository outside of your terminal session? I don’t think that’s reflective of how most people work.
Are you saying that it gets out of date but that doesn’t matter? If that’s the case, then it’s a strong hint that the information isn’t as useful as you assume. What’s the point in constantly, repeatedly showing incorrect information?
Are you saying that you work around the problem by hitting enter whenever you want an update? Then aren’t you doing the same thing as your colleagues who you mention struggle with Git? Hitting enter in your case is essentially a shortcut for running `git status` over and over, except you are doing it with literally every command you run instead of only when you need to.
> Also how is "enter" less convenient than literally any other command that you'd still have to type and run to get up-to-date information in a command line?
The issue is the space and attention used by repeatedly showing outdated Git information. Space and attention are at a premium in a terminal window; you can’t just dump all the information available to you in there for free.
> Are you saying it doesn’t get out of date? i.e. you never change the state of the repository outside of your terminal session? I don’t think that’s reflective of how most people work.
That's what I do, I use git directly for trivial stuff and lazygit for more complex stuff, both inside the terminal.
> Space and attention are at a premium in a terminal window; you can’t just dump all the information available to you in there for free.
That's true. I've tried "absolutely nothing except %", "very long and fancy prompts" and the current directory (often aliased), the current git branch and % is what works well for me.
To a lesser extent, I've done a few Java version migrations so it can be useful for the Java version to be printed so it's obvious if I've got the wrong JDK enabled. Python fell under this, but I don't think I'll have to worry about having one project be Python 2 while the others are 3 anymore.
I like this approach. I tried using starship.rs but I have to say it does far more than I want it to and makes me feel like I'm not in control of my shell (e.g. it pulls a schema via an URL without any knowledge from me that it does so).
As a result, I've written my own small and concise PS1 which covers all my use cases:
## Add this to ~/.bashrc
force_color_prompt=yes
## show: user+hostname (if ssh), conda, venv, guix, and git
function prompt_command {
## styles and symbols
local RESET='\[\033[0m\]' ; local BLD_GRN='\[\033[1;32m\]';
local BLD_YLW='\[\033[1;33m\]'; local BLD_PPL='\[\033[1;35m\]';
local BLD_CYN='\[\033[1;36m\]'; local BLD_WHT='\[\033[1;37m\]'
local ITL_YLW='\[\033[3;33m\]'; local SEP='⋮'
PROMPT_DIRTRIM=2
export PS1=""
if [ -n "$SSH_CONNECTION" ]; then
PS1=${PS1}${BLD_CYN}'\u'${BLD_YLW}'@'${BLD_GRN}'\h'${RESET}
fi
if [ -n "$CONDA_DEFAULT_ENV" ]; then
PS1=${PS1}${SEP}${ITL_YLW}${CONDA_DEFAULT_ENV}${RESET}
fi
if [ -n "$VIRTUAL_ENV" ]; then
PS1=${PS1}${SEP}${BLD_WHT}${VIRTUAL_ENV##*/}${RESET}
fi
if [ -n "$GUIX_ENVIRONMENT" ]; then
PS1=${PS1}${SEP}${BLD_GRN}'GUIX'${RESET}
fi
if [ -e .git ]; then
PS1=${PS1}${SEP}${BLD_PPL}$(git branch --show-current)${RESET}
fi
PS1=${PS1}${SEP}${BLD_GRN}'\w' # short directory
PS1=${PS1}${BLD_YLW}'▶ '${RESET}
}
export PROMPT_COMMAND=prompt_command
The GIT status prompt is immensely useful. Not as useful, but still occasionally useful, are the prompts for language / tool versions. And how much time did the last command take. I make a regular use of that when I don't need sub-second timings.
If that makes me "thinking I am clever" then by all means, spend your life believing that. It increases my productivity though.
If your shell is ZSH and you have `setopt autocd` in your .zshrc (though I think this setting is on by default):
export PS1="%~; "
this will result in the prompt: `~; ` where the ~ will change to a path relative to home.
Why do this? Well; it means you can select and paste any line in your history: your prompt becomes part of setting the proper context and is part of the command. Just select the entire line. :D