$
#
%
> $
#
%
>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
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.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.
Left: confused and no prompt
Middle: proficient and with prompt
Right: proficient and no prompt
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 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?
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?
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.
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.
I think you are conflating two separate things.
I don't care for starship or prompts which show git status information. But, when interacting with git, I do often type git status.
That being said, I don't struggle with git.
Really, when I don't need status information, I don't want the horizontal space taken up with an unnecessarily noisy prompt.
So it looks like:
me@pop-os 09:19:20 files: 49
~> /path/to/cwd
$
by default and in a git repo: me@pop-os 09:20:14 files: 18
~> ~/dev/work/projects/someproject
[ git ~ feature/some-feature || Add: 0 Mod: 1 Del: 0 Unt: 0 ]
$
in a venv: me@pop-os 09:20:14 files: 18 (venv: my-venv)
~> ~/dev/work/projects/someproject
[ git ~ feature/some-feature || Add: 0 Mod: 1 Del: 0 Unt: 0 ]
$
Note, these all use different font colors to be distinguishing.* username if it's not "me"
* indicator if in `screen` or `tmux` session
* `cwd`
* in reverse-video or bold, on terminals that support that, to stand out
All these things have been useful many times.
Most often, which is shells on local laptop, the prompt is only a reverse-video cwd. The extras appear for less-usual situations.
I should add Git info.
If that makes me "thinking I am clever" then by all means, spend your life believing that. It increases my productivity though.
If it increases your productivity, then it’s the opposite of what I’m talking about.
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
Fast and easy to grok.