6 ms·
I do like to have colorized output for my interactive CLI tools, but I will never understand a prompt other than "$" or "#". Do people really need to continuou
by eddieh 6y ago
I do like to have colorized output for my interactive CLI tools, but I will never understand a prompt other than "$" or "#".
Do people really need to continuously see all the noise like the host name, their username, the working directory, the date, or even their current branch?
Is hostname, whoami, pwd, date, git branch, and git status really to cumbersome? At least with hostname and branch I'm usually piping to pbcopy anyway.
FWIW, the -F option for ls is really nice too.
- xiconfjs 6y agoabout hostname in the prompt: if you are logged in to a bunch of server debugging a problem, it's good to see from the first sight on which system you are executing a command.
- enriquto 6y ago> I will never understand a prompt other than "$" or "#" I agree with that, but some legit useful information in the prompt is the exit status of the previous command. So you may have a slightly less minimalist PS1='$?\$ ' which is typically seen as "0$" unless something went wrong. Another legit and useful information is the number of background jobs (set up to the empty string for the common case of zero jobs). Other information like the cwd, the time or the git branch are of course idiotic.
- isatty 6y agoFor my local machines I don’t bother with hostname, whoami or date but the former two is essential on remote servers, so it’s good to have as defaults. pwd is really useful since I’ve tons of terminals on tmux and typing pwd gets repetitive real quick.
- CamperBob2 6y agoDo people really need to continuously see all the noise like .... the working directory...? I can't imagine using a CLI prompt without knowing what directory I'm in. How would that even work?
- eddieh 6y agoI guess I usually know what directory I'm in and if I ever need a reminder I use pwd. With at least 6 months of commands in ~/.bash_history $ history | grep pwd | wc -l 10
- kergonath 6y agoI usually have ~20 terminal windows open, some of which have sessions opened on 4 different machines. If the host name and current working directory are not in the prompt, I need to check both every time I switch windows. Otherwise there’s no way I won’t make a mistake and do some stuff in the wrong place or on the wrong server. I can accept that my use case is not typical, but these things are actually useful.
- aspaceman 6y agoI'm an anxious ls-er. I unconsiously ls while I'm thinking in a directory, so I usually have a pretty good sense of my location.
- necrotic_comp 6y agoIf you do work on a number of different machines, in production and in dev, knowing what host you're on, what directory you're in, etc. helps avoid errors like killing a process in prod when you thought you were in dev. While writing code, it's helpful to know what branch you're on with git, so you don't accidentally commit code to the wrong branch, etc. I typically have something like 30-40 terminals open at a time, grouped into windows in tmux, so having everything categorized and visible at a glance is kind of a necessity.
- eddieh 6y agoI have ssh sessions to remote machines, I use multiple terminal windows, and multiple tabs. I don’t use tmux, is there something about tmux that makes it hard to know where you are?
- necrotic_comp 6y agoThere's nothing specific about tmux that makes it hard to know where you are, but it does let you keep any number of terminals open on one screen, which is super-helpful, but requires a lot of mental overhead to keep track of where everything is. If you're able to keep track of the context of 50 windows without a prompt, more power to you, but that's not something I can do and I require some signage to ground where a specific prompt is.
- Izkata 6y ago> all the noise I'm sure it takes some getting used to, if you're used to something more minimalistic, but it isn't noise to me. It's a persistent indicator of where you are, and is usually easily ignored. The benefit of it for me is that I always have "where am I, where are files in relation to here" in the back of my mind. While switching terminals, if what's in my mind doesn't match the prompt it's really jarring and hard stops me from doing something stupid on the wrong system or directory or as the wrong user.
- mmphosis 6y agoHere's a snippet from my bash_aliases ... ### PROMPT ### function user_host_pwd() { printf "%c " '-' user -n printf "%c" '@' violet printf "%s" "${HOSTNAME%%.*}" normal printf "%c" ':' path "${PWD}" } -() { user_host_pwd ; } prompt_command() { local current="$USER@$HOSTNAME:$PWD" local last_cmd if [ "$current" == "$USER_HOSTNAME_PWD" ]; then last_cmd="#$(history | tail -n 1 | sed -e 's/.*[0-9] //' | cut -d ' ' -f 1)" for cmd in $COMMANDS_USER_HOST_PWD_PROMPT do if [ "#${cmd}" == "$last_cmd" ]; then USER_HOSTNAME_PWD="" break fi done fi if [ "$current" != "$USER_HOSTNAME_PWD" ]; then export USER_HOSTNAME_PWD="$current" user_host_pwd fi } COMMANDS_USER_HOST_PWD_PROMPT="cd ssh sudo su login $(sed -e '/^#.*$/d' -e '/^$/d' -e 's@^.*/@@' /etc/shells | uniq | xargs)" PROMPT_COMMAND=prompt_command PS1='$ ' [ "`id -u`" -eq 0 ] && PS1='# '
- zvr 6y agoIt all depends on your mode of working. You want to have information showing the current state of stuff that changes. If you only work as the same user, having $USER in the prompt is visual clutter, and you very soon learn to ignore it -- then why have it? If you only work as one user or "root", you can encode this difference in the "$"/"#" character. Current directory... is very useful. I have worked for years without it (before it was available) and it really made a difference. Yes, it just saves you a command (pwd, dirs, ...), but it's nice to have this info right there. Where I would agree is the git branch info. How do people use it in their prompt? This is filesystem-level data, totally independent from the current shell session. To give an example: I have two terms (shells) and in both I am in ~/mydir. They both show got branch "master". In one of them I change to another branch. That window's shell prompt gets updated but the other windows still shows me as being in "master". Do people press enter before each command to have the prompt updated to actual values?