Starship.rs: minimal, fast prompt for any shell(starship.rs) |
Starship.rs: minimal, fast prompt for any shell(starship.rs) |
> This preset will become the default preset in a future release of starship
It also links to an open issue on the GH repo about it [1] (although that issue is 2 years old and doesn't seem to be top priority.)
Other fonts work to. I use Fira Code myself.
Besides the product, the community is pleasantly awesome as well. I've contributed a module to it and the maintainer has done a good job reviewing and testing. Heck, they even have a Discord server for contributors.
I tried out starship about three years ago and it is so fast I don't notice its execution time at all. I switched and haven't looked back.
$
#
%
>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.
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.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.If that makes me "thinking I am clever" then by all means, spend your life believing that. It increases my productivity though.
* 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.
Trying to get it working on WSL (Ubuntu 20.04 and Centos) as well as MSYS just wasn't happening. On the few occasions I did get it working, it was unbearably slow. Simple commands would have sometimes half a second of delay. I could time what was causing the slowdown and disable some of it, but by the time I got it bearable I had disabled basically all of Starship. Then there were font-related issues on top. Ugh.
I hope others have a better experience than I.
Rust is not a user feature, it's an implementation detail.
<cue people telling me I should consider Rust a feature>
I think it goes well with the fish shell: it's much nicer than the default, without requiring customisation.
With the transient prompt, you can have things like Git or Kubernetes status on your “main prompt”, but without always printing them in the terminal for the commands you ran previously. It keeps the history much cleaner, and therefore more pleasant to scroll back up. I've also configured it to print the time when the commands were executed to the start of the lines.
These context clues are especially important for newcomers to the command line. A CLI newbie who sticks with it might eventually progress to the point where they decide to ditch Starship, or to ditch fish, or to ditch both, but until they get to that point, the solid defaults and OOTB features of these two have a lot going for them. Meanwhile sticking someone in a '$ ' with no coloring, no autocompletion, and no real clues in the terminal itself is more likely to lead to them just giving up entirely.
https://github.com/srid/nixos-config/blob/master/home/starsh...
Incidentally, starship also gives a visual indication of whether you are in the nix shell or not, which is pretty handy when using direnv:
Having 8 (or more) colors help when dealing with information though, at least when you need to get a quick result and not just dig into the man pages.
Here is what a minimal shell prompt looks like:
$
Here is another one which only uses the shells own facilities: current-directory@hostname $
Running a complex piece of software every time the shell needs to display it's prompt, is not "minimal", regardless of how fast and well written said piece of software is.Some things that you use regularly should be kept as minimal and as stable as possible. To me that includes the shell prompt, editor, browser for example.
Do the people who use this (along with terminal emulators that require you install things on the host to get the full power) just not use other machines and/or install stuff like this on them? Just seems odd to me personally but I’m interested in how others use it. Do you only use your own computer/terminal so it’s not an issue?
Thank you!
Surely it is some work to ensure your user environment are all the same across different machines. But it is also liberating as you are no longer limited to choose the few common features available everywhere.
Another minimal prompt: https://lib.rs/crates/pista
https://github.com/rollcat/etc/tree/master/cmd/prompter
It's quite portable (didn't test on Windows though); ~170 lines of Go; no dependencies outside of stdlib; calls no external commands; supports SSH, git, Docker, nix, and virtualenv; extremely simple to hack on.
`custom` spawns a child process of your shell, so it's probably being slowed down by a slow shell init script. If the custom script you're running doesn't require your full shell customization to work, you can provide a custom shell command [0], passing an argument to not use your shell config. For instance: `fish --no-config` or `bash --noprofile --norc`
Or should I do it only on toy machines, risking different experience between them and production.
No, thanks. Plain bash will suffice. Just like it did for so many years.
Thanks.
I usually use simple ^ but having something like there would be nicer.
What makes this "infinitely customizable" aside from being turing complete?
I don't see anything but ... a prompt.
So yes, it is kind of a competitor to p10k, but not zsh. It's just the prompt, and it just focuses on being a very good prompt tool.
Need to check on how to handle it on shells with no root access.
I'd like to have some usefull information about my session but also prefer when my input begins from the first column.
Personally, I find the extra blank line to be a useful visual separator between lines of output. Particularly useful when running commands with lots of output or 'cat'-ing files or logs.
I use that for starship information and the prompt is just the return code p[lus a character.
Sure, but keep in mind that in the case of open source software plenty of people will choose software written in their favorite language so that they can potentially contribute to it. Or simply because they feel more connected to something that is written in their favorite language. So I don't think it's completely irrelevant.
If it was written in JS or python I'd already start worrying about what package manager to install it with in which environment, installing it globally is an anti pattern but symlinking it to .local/bin might complicate it.
So IMHO, the language something is written in is not just an implementation detail, it informs me in how well it will perform.
That, in essence is the problem "X in rust" normally means "I've written something of low value IN RUST. Gimmee upvotes". Come back when the project is interesting regardless of the language.
Rust has memory safety built in (unless one goes VERY out of their way to nullify it) which to many, myself included, is a selling point. F.ex. I wouldn't be interested in the userland tools rewrite if they weren't in Rust.
> Rust is not a user feature, it's an implementation detail.
It is that, yes, but not only that. Again, memory safety. And as another poster pointed out -- statically linked binaries. That helps a lot with certain deployments.
Also consider that HN might not be the place for you if mentioning implementation details are ticking you off. That's more or less how this forum started in the first place: people discussing implementation details.
Rust is the new C. It communicates that something is fast, but also secure, and new or a modern reimplementation of something old. So, in that sense, is it a user feature because it has established itself in a way that tells the user some important details.
If you don’t care, ignore it. Why should it bother you so much?
I think it has become a significant user feature.
I think you might just be prejudiced. Do you have the same reaction to, say, SQLite?
https://www.sqlite.org/index.html
> SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine.
Rust’s memory safety definitely makes it a user feature.
Unless we are talking about unicode support. Indeed, the software should make a basic inquiry to see if the shell/terminal emulator supports unicode and fall back to ASCII if not. But there is a difference between "I don't support unicode" and "my unicode support is broken": the latter needs fixing, and emoji are actually a good test case to see if you really support unicode.
If it increases your productivity, then it’s the opposite of what I’m talking about.
It can. With a little help. I use this:
I have. It's a decent chunk of work. It's a whole lot more work to do it well. Did you remember to handle the situation where the git repo is so gigantic that running `git status` takes half a minute? Or the case where there is a .git folder somewhere but permissions are wrong or it crosses a mount barrier so `git status` prints a page of text to stderr? Does the way you're finding the current branch handle the case where HEAD doesn't point to a branch?
The only way your prompt "already does" this stuff is if you've spent a whole lot of time configuring it and tuning it, or if you're already using something like oh-my-zsh. And if you're already using something like oh-my-zsh, well, starship is just a competitor to (the prompt portion of) that.
It's a decent chunk of work. It's a whole lot more work to do it well.
There's no doubt about that. You might even learn a thing or two about your shell in the process. Is that considered a bad thing nowadays?People want something easy to use with good defaults. If that wasn't the case, shells wouldn't have a hundreds of plugins dedicated to customizing the prompt.
If you need to invoke a program for every prompt, when the alternative is to just let the shell do it's thing, it's no longer "minimal", period.
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.
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.
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.
The type of complaining you're doing is also nothing new, because exactly the same occurs under those posts when it's the language de jour. A few years ago when it was all about Go, you could look in the HN comments and see people complaining exactly the same way about Go and the Go community.
But it's an interesting observation, don't you think? Why is it that just by adding "... in Rust" you can almost guarantee that people will roll their eyes and think "oh, not another one".
Other languages do not carry such stigma, why does Rust have such reputation?
This is all wild speculation on my part, so please take it with a large grain of salt. I welcome alternative explanations or experiences.
part is the important term here.
Using a particular language signals a certain subset of qualities and broadcasting those helps people filter what they are interested in.
No, we are not. "minimal" has a defined meaning, and "minimal" and "minimalism" as a design philosophy are not the same.
$
It looks like this: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.
As the OP, this is a big part of it. Rust might be a great language, but people announcing they rewrote grep (for example) in rust doesn't mean they've done anything special. The rust language team did something special. The person making the announcement just took somebody else's idea and reimplemented it for very little reason.
Great! You learnt enough to reinvent the wheel. Now do something useful.
I see one dictionary definition is "the least possible". Seems like the least possible prompt is no prompt at all, but it's really just a matter of opinion ;)
Why? I just point out that what happened to Haskell can happen to Rust, and for much the same reasons.
Are you saying that Haskell never got wide adoption because its advocates were too loud?
Even if you claim that I'll not believe it. Haskell is legitimately difficult for many annoying reasons, not least of which are the endless compiler variants.
I love the language and worked with it professionally for over a year, but I can’t stand everything around the developer experience and community.
Rust is a breath of fresh air.
Also they might have made the mistake of judging a very big and heterogenous community by a few zealot loudmouths (and every community has those).
Informed and objective people shouldn't judge like that but I think it reinforces a preconceived notion that they already have.
The human brain can betray us like that. If you already dislike something, practically every criticism towards it, no matter how small, makes you immediately go: "A-ha! This thing is bad! I knew it!"
That by itself is only a cause. What's the effect, what's the symptom of this attitude, what are the practical observable results? Gatekeeping? Rude forum responses? (I know OCaml partially suffered from that and they can be fairly elitistic; when you ask something fairly normal nowadays like "what's the preferred package manager?" or "how do you build a project?" is sometimes met with smartass responses like "what's a project?")
> I love the language and worked with it professionally for over a year, but I can’t stand everything around the developer experience and community.
Sums up my experience with several development communities, yep. I can relate.
> Rust is a breath of fresh air.
I feel the same, the community is extremely pragmatic. I've met a few a-holes but they were a very, very rare exception. 99% of everyone I interacted with was just like me: they were looking how to get the job done AND write idiomatic and efficient code.
This really depends. I don't care about some abstract notion of a community BUT if I can't get basic stuff done because documentation is not good and the official forum responses are not helpful then yes, I absolutely will abandon the language.
To this day, languages differ a lot. I.e. in Elixir and Rust I can just add dependencies to a file (Rust even allows you to add the dep via a CLI command) and then reference it in your code a minute later, issue a command and your project is compiled and runs and you see the result.
Now ask me how much time I spent fiddling with OCaml's `dune` and `esy` which are a project manager and a dependency manager respectively. Took me an entire weekend to get one simple code to compile with a singular CLI command, and then run it. And community was not helpful: "check the docs", which I did 15 times probably over the course of that same weekend.
To go back to your point, friendly / welcoming community is just a bonus. The community has to be helpful above everything else. Some people are noobs. Some people like myself are senior BUT are unwilling to start over and are just looking for "how to do X and Y without spending a full day?". Some people are trying to make a presentation to advocate for the technology on an internal meeting. Examples abound.
I am not an experienced moderator (nor I ever want to be) but I've witnessed significant differences in how various programming language (or just a framework) communities act, and how helpful they are. It absolutely isn't identical or even close. Some are downright off-putting.
Finally, I make no claims about Haskell in any way except only one thing: when I saw its huge combinatorial explosion of different compilers, I gave up on the spot. Give me 2-3 options and leave the rest to the enthusiasts.
In case you're interested into how Haskell handles some of the specifics you brought up:
> in Elixir and Rust I can just add dependencies to a file (Rust even allows you to add the dep via a CLI command) and then reference it in your code a minute later, issue a command and your project is compiled and runs and you see the result
This is also true of Haskell using Cabal. Cabal has some rough edges. Perhaps it's not as ergonomic as the Elixir or Rust equivalents (I've never used them) but you can at least do that.
> when I saw its huge combinatorial explosion of different compilers, I gave up on the spot. Give me 2-3 options and leave the rest to the enthusiasts.
This issue has been resolved with the introduction of the GHC2021 language edition. Just use that. No need for any other language extensions as a non-expert, except maybe in very special cases.
(By the way, there was never a combinatorial explosion of compilers. Almost all language extensions simply remove restrictions. But I understand how people could interpret it that way, and GHC2021 is a very simple way of resolving the misunderstanding.)