←back to thread

457 points benoitg | 8 comments | | HN request time: 0.69s | source | bottom
Show context
m000 ◴[] No.44367731[source]
I would be very curious to see an age demographic chart of people using e.g. Starship.

Personally, over time, I have stopped caring too much about prompt customization. I concluded that, no matter how carefully you curate your prompt, 90% of the information shown will be irrelevant 90% of the time*. After a while, your brain will start perceiving this as visual clutter and filter it out, to the point you may even forget the information is there, right in front of your eyes.

And for the things that matter, you probably need more details than any prompt can show you. E.g. are there changes in your git branch? Ok there are, good to know, but which files have changed? Just knowing that there are changes is not really actionable information. You need to run additional commands to get actionable details.

* the numbers are completely arbitrary, but you get the picture

replies(12): >>44368415 #>>44368447 #>>44368864 #>>44369236 #>>44369278 #>>44370150 #>>44370843 #>>44371011 #>>44371393 #>>44373149 #>>44376069 #>>44385108 #
1. deathanatos ◴[] No.44368447[source]
As a counterpoint, one of the most useful customizations I've made to my prompt is to emit the exit status of the prior command. Knowing that something failed is a useful signal, esp. when sometimes the thing failing just fails to emit any output that indicates that it failed.

I only emit it if the prior command fails, too, so it doesn't clutter things the 90% of the time things are working.

  » true
  » false
  (last command returned 1.)
  » 
I also translate signals, so I get "last command exited on SIGSEGV", or so.

It's also useful the other way: when a program emits and error and exits with "success".

replies(4): >>44369265 #>>44369378 #>>44369845 #>>44373145 #
2. __float ◴[] No.44369265[source]
I like the exit code feature a lot; Starship does that with my config in a subtle color change.

My shell customization is largely throwing Starship in (so it looks the same on all the machines I use -- Ubuntu servers at work, macOS at home, nixOS/Fedora/etc. servers for personal use.) and a starship.toml I wrote once and now leave alone.

3. m000 ◴[] No.44369378[source]
That's useful indeed. Did you custom-code it, or is it e.g. an ohmyzsh plugin or something?
replies(1): >>44373577 #
4. tclancy ◴[] No.44369845[source]
Oh, how do you automate that? I usually add a "& say done | say failed" to long-running tasks if I remember to do it.
replies(2): >>44370766 #>>44373575 #
5. teo_zero ◴[] No.44370766[source]
In bash, it's enough to remember that $? expands to the exit code of the previous command, and $((x)) evaluate x as an integer expression, including the ternary operator x?y:z.

For example the following prints the exit code in green if zero, in red otherwise:

  PS1='\[\e[$(($??31:32))m\]$? \[\e[39m\]'
6. wocram ◴[] No.44373145[source]
This and command duration if the command ran longer than 10 seconds are the most useful things to add.
7. deathanatos ◴[] No.44373575[source]
https://github.com/thanatos/dotfiles/blob/master/shell/zsh/p...

That was my prompt when it was written in zsh. Sort of like TFA, I've since moved to Rust:

https://github.com/thanatos/dotfiles/blob/master/zsh-prompt-...

I think (if I am reading TFA's code right) unlike the article, I'm using zsh's module functionality, so the Rust here is a .so that is loaded directly into the shell's memory. (I.e., I do not have to fork/exec a separate Rust bin to compute the prompt, though I think zsh might fork-but-not-exec for computing the prompt itself.)

The latter is, of course, somewhat more complicated in some senses. (Esp. on macOS, which work forces me to use, where dlopen(2) is just utterly insane.)

8. deathanatos ◴[] No.44373577[source]
I custom coded it. (Details: https://news.ycombinator.com/item?id=44373575)