12 ms·
Colorize Your CLI
- tzury 6y ago`diff --color=auto` is nice, but `vimdiff` is superior
- ipozgaj 6y agoThere is also `colordiff` which works both as a standalone diff tool, but also as a colorizer filter for other diff tools. For example: diff -u a.txt b.txt | colordiff
- petepete 6y agoGit ships with `diff-highlight` which is more than enough for me. I use the following config. [core] pager = /usr/share/git-core/contrib/diff-highlight | less [color "diff-highlight"] oldNormal = red oldHighlight = 16 bold red newNormal = green newHighlight = 16 bold green
- erichdongubler 6y agoI myself have really enjoyed `delta` and the variety of configuration it has: https://github.com/dandavison/delta https://github.com/dandavison/delta
- atdt 6y agoThe GitHub link to Generic Colouriser points to an outdated and unofficial fork. The canonical one is at https://github.com/garabik/grc https://github.com/garabik/grc.
- danyspin97 6y agoFixed, thanks you for pointing this out!
- pen2l 6y agoI think in this day and age we should be making bigger jumps than wanting color in our CLI. We should have more than one font, we should have pictures. We're visual creatures, us humans. I think something like Jupyter, with in-line images et al is the future, or should be, at least.
- danyspin97 6y agoI agree, but we're limited by terminal emulators. Not counting images in terminal (which can be done with a protocol few terminal supports), we don't even have Font Ligatures widely available. https://github.com/tonsky/FiraCode#editor-compatibility-list https://github.com/tonsky/FiraCode#editor-compatibility-list
- Icathian 6y agoI strongly disagree. If we're going to use a TUI, it should embrace what it is. Turning it into a watered down GUI does not work to its strengths nor serve the needs of the users still working with it.
- smabie 6y agoI dunno, Emacs works really well, and I line images and stuff is really nice. A good example of this is that you can have inline rendered LateX in your text buffer. And when you need to edit it, it turns about into texts. Also inline graphs in org-mode is super nice.
- bmn__ 6y agohttp://blog.z3bra.org/2014/01/images-in-terminal.html http://blog.z3bra.org/2014/01/images-in-terminal.html https://askubuntu.com/questions/97542/how-do-i-make-my-terminal-display-graphical-pictures https://askubuntu.com/questions/97542/how-do-i-make-my-termi...
- GhostVII 6y agoI feel like we need a complete rewrite of terminal emulators/bash/whatever. It should be super easy to make a CLI with nice colors, good loading icons, etc. without having to deal with all kinds of color codes and cursor movement. When I press "enter" while a script is showing some progress bar, or resize the terminal window, it should handle it nicely like every other application. I use the command line whenever possible over a GUI application, but sometimes I wish it wasn't still stuck in the 80s. Keep the speed an simplicity (I don't want images or anything), but make it easy to make robust applications with a clean text based UI. I shouldn't still have ghosting in my Vim setup, it's 2020.
- mulmen 6y agoI kinda like using tooling with 40 years of refinement. Is it perfect? No. Do I need to resize a window with a progress bar? No. Would it be nice? Yeah, I guess. Am I underestimating the benefits? Almost certainly. But what are the other sharp edges that come with the shiny new thing? Would it be an electron app? Yes, probably. Would it work? Maybe, in a couple years. There would be some major bugs first, and a lot of dead batteries. I don’t think new devs are specifically worse than old ones. I do think there is immense value in using something that has been actively improved for your (well, at least my) entire lifetime. There are lessons buried in there we don’t even begin to understand. Starting over means forgetting those lessons too. The grass is always greener on the other side of the fence is what I am saying.
- cuddlecake 6y agoThere are a lot of "Maybe"s in your second paragraph. I'd say, yes, there are a lot of lessons buried in old code, but often, there is an equal amount of baggage we are too fearful to abandon because of backward compatibility and "bug became feature"-situations. And even then, it's not you who is abandoning that, which makes the attitude even more baffling to me.
- michaelmure 6y agoIt looks to me that the reality is closer to "40 years of hack over something that was not meant to be a standard (a popular hardware terminal from the 80s)". I'll give you just one example of the madness that is sometimes required: the escape code \e[1m is doing "bold on". It's counterpart to reset \e[21m, is supposed to do "bold off", but in practice some terminals do "double underline" instead because this standard is not a real standard. As there is also no real way to detect capability, the only reliable way to do "bold off" that I could find is to intercept the stream of data sent to the terminal to compute the attribute state. When you want to do a "bold off" you do a \e[0m "reset all" instead and sent the control character to set the state again without bold [1]. A new standard would also allow to reliably use features like displaying images or links. [1] https://github.com/MichaelMure/go-term-markdown/blob/master/renderer.go#L284-L294 https://github.com/MichaelMure/go-term-markdown/blob/master/...
- rudiv 6y agoLove starship. Fast, easily customizable, and best of all works on Windows as well as macOS/Linux. (Unsure about BSD, but I presume that as well)
- monokh 6y agoReally tempted to install starship but I also do a bunch of sensitive stuff with my terminal. Should I be worried about using this? I understand it's open source, yet still not confident.
- danyspin97 6y agoKeep in mind that having bash history is already a treat since `~/.bash_history` is readable by every program you run. If you want to be 100% safe you could just monitor the process and see if it opens any internet connection but I am confident it is just a local program.
- O_H_E 6y ago> treat *threat
- matchai 6y agoStarship maintainer here. I'm happy to answer any questions have about how it works. Every render of the prompt is fully stateless. Starship has no tracking, telemetry, and never calls home. :)
- 1_player 6y agostarship looks good on paper, but the fact that all plugins are by default enabled (from what I can tell from the docs) is a no-go for me. Why do people need all that information on their prompt? I understand showing the git status, but is it really necessary to know that your battery is discharging and you're currently using node v10.12.3 and elm v1.2.3 every single time you run a command in some directory?
- matchai 6y agoStarship can be quickly configured to have a select few "modules" enabled. This can be configured with `prompt_order`, documented here: https://starship.rs/config/#prompt https://starship.rs/config/#prompt I, for one, like to know what version of Node will be used when I'm jumping between projects, so I can know which features are available to me at runtime. Eventually we'd like to include an interactive configuration tool to help folks find a configuration that meets their needs.
- IggleSniggle 6y agoOne of the biggest upgrades from using fish is syntax highlighting / autocompletion. You can get fish-style syntax highlighting and autocomplete in zsh (which has the advantage of being more interoperable with bash generally): [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting https://github.com/zsh-users/zsh-syntax-highlighting) [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-autosuggestions) Poster mentioned "modern alternatives exist" with good colorization options. Some of my favorite colorized feature-rich alternatives: ls -> [exa](https://github.com/ogham/exa https://github.com/ogham/exa) cat -> [bat](https://github.com/sharkdp/bat https://github.com/sharkdp/bat) du -> [ncdu](https://dev.yorhel.nl/ncdu https://dev.yorhel.nl/ncdu) diff -> [delta](https://github.com/dandavison/delta https://github.com/dandavison/delta) In combination with all of the above, [fzf](https://github.com/junegunn/fzf https://github.com/junegunn/fzf) suddenly becomes a syntax-highlighter preview-pane via leveraging bat (or delta, as the case may be).
- danyspin97 6y agoPoster here! ble.sh gives syntax highlighting for bash just like fish and zsh. I personally don't like zsh because it seems over engineered and fish have some design problems (I don't think they have yet fixed them). The feature-rich alternatives you mentioned are exactly what I was thinking about (and using daily!).
- IggleSniggle 6y agoThere are a few things about zsh that "feel better" than bash (especially arrays), but given the ubiquity of bash, if I can get the same general quality-of-life upgrades that I experience from the zsh community add-ons, I may need to give ble.sh a go. Edit: I gave ble.sh a try, and it is super-cool-magic, but does feel slow with quite noticeable input lag.
- Morgangeek 6y agoI've also aliased cat to bat but it causes me issues when I redirect the output of cat (bat) without \cat to a file as then the file contains color codes that are not expected by other users and tools and cause some tools to not behave correctly,while the issue is invisible to me (unless reading the generated file with \cat)
- AlexDragusin 6y agoFor Windows, one could use this small color utility I've made last year, ColorThis https://www.alexdragusin.com/#ColorThis https://www.alexdragusin.com/#ColorThis
- roywiggins 6y agoColorful prompts remind me of my time playing MUDs. The better ones did a good job colorizing everything so you could navigate almost by color alone.
- Tade0 6y agoSomewhat related: My friend is developing a colour palette based on Solarized: https://github.com/jan-warchol/selenized https://github.com/jan-warchol/selenized but with more perceptual uniformity.
- digisign 6y agoI like it better but don't understand the desire for a near dark cyan background that each promotes.
- O_H_E 6y agoalternate colours based on the same principles here: https://github.com/jan-warchol/selenized/blob/master/the-values.md https://github.com/jan-warchol/selenized/blob/master/the-val...
- O_H_E 6y agoLooks really nice . Thanks for sharing
- tvb12 6y agoIt looks like he's only doing the dark mode. I wonder what selenized-light would look like.
- samsaga2 6y agoAs developer I think we use too many colors everywhere. It is really necessary? Some terminals looks like a rainbow festival. A color for the user, a different color for the hostname, another one for the git branch... It is a directory? Let's add a new color. I think is too much. I like to use themes like minimal-theme [https://github.com/anler/minimal-theme https://github.com/anler/minimal-theme]. My eyes appreciate it.
- CapsAdmin 6y agoSounds like the problem is not colors, but the amount of stuff we're differentiating then. You could say the same thing about making things bold, italics, shades of grey, etc. I would think people recognize different colors better than shades of grey or bold text though. Interestingly, in a lot of Japanese advertisement it feels like all the ways of making something stand out have been exhausted.
- sgt 6y agoI agree. How about just reading the text? The human brain is excellent at quickly skimming through text and recognizing patterns. We don't need colors.
- nomel 6y agoDifferentiating by, and extracting meaning from, color is a very ancient and important part of our visual system and every day life. Why wouldn’t you want to take advantage of it, living in a black and white world?
- kergonath 6y agoIt’s a good thing we can adapt it to our taste, then.
- IggleSniggle 6y agoTo my brain, syntax coloring makes recognizing the shape of some code a more rapid/fluid process. It also provides a nice feedback loop for potential typos (in my cli setup, a misspelled command will be red instead of green, a string will be yellow, etc) so that you can catch an error before you execute/commit. Outside of all of that, I enjoy the rainbow festival aesthetic. I coded a lot as a kid for fun, and was good at it, but got away from it as an adult. I think a huge part of transforming back into an enthusiast was all the attention to themes, fonts, ligatures, autocompletions, etc. I really enjoy "talking" with my computer, and all of the styling gives a sort of pseudo-personality, as the computer responds to my syntax with different colors as I'm writing it. That said, you might not like rainbow personalities! That seems to make you an outlier, but it doesn't matter! One great thing about code is that it can be easily adapted to a users preferences...that is, as long as you're using tabs for indentation and spaces for alignment ;-)
- deleted 6y ago[deleted]
- oweiler 6y agoInstead of `ls` I use `lsd` https://github.com/Peltoche/lsd https://github.com/Peltoche/lsd.
- ausjke 6y agoNice article, 'starship' is new to me, just tried out, a bit verbose and took too much line space for me. 'highlight' should be replaced by 'bat' these days. 'grc' is nice and I first time learned it here. After read it and tried out, I just added 'grc' to my tool kit(though ubuntu 18.04 misses /etc/profile.d/grc.bashrc and I had to download it from github)
- always_left 6y agoJust looking at the homepage of starship, I don't really understand what benefits it has. It says fast but simply has a gif? I understand a bit more via the docs, but it's annoying the home page doesn't really show any benefits and just wants you to install it asap.
- IshKebab 6y agoAlso set `CLICOLOR=1`. See https://bixense.com/clicolors/ https://bixense.com/clicolors/ A fair number of tools support it.
- clintonc 6y agoI find myself wishing for a CLI "design system". For example, given a script that calls some APIs (reads and writes) and does a couple of calculations, what is the best way to use color and space to produce understandable and useful console output?
- eddieh 6y agoI 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 ago
- dleslie 6y agoColorizing is a red herring; it's akin to syntax highlighting: it's nice, but if you need it to determine important information then something's amiss. I'd much prefer consistent and predictable information conveyance. Ie, I don't need Midnight Commander to be lit up like a christmas tree because I know immediately what information is displayed in its tables and panes.
- a1369209993 6y ago> but if you need it to determine important information then something's amiss. Not untrue, but define "need"; as eg [0] points out, distinctive colors make it much easier to notice things. (On the other hand, TFA seems to be advocating precisely the kind of syntax-based ice-cream-sprinkle-soup coloring that makes it harder to notice things, so not exactly the most convincing presentation there.) 0: https://buttondown.email/hillelwayne/archive/syntax-highlighting-is-a-waste-of-an-information/ https://buttondown.email/hillelwayne/archive/syntax-highligh... 0 dicussed: https://news.ycombinator.com/item?id=23902124 https://news.ycombinator.com/item?id=23902124
- dleslie 6y agoColour is a bad tool, even if it is an effective tool; a not-insignificant portion of the population has difficulties with colour. Then there's that not all displays render the same, and not all editors colourize the same. Syntax and layout are superior.
- a1369209993 6y agoI am immensely opposed to the notion that something being difficult or even wholely unusable for a "not-insignificant portion of the population" makes it a bad tool, rather than merely a situational one to which alternatives are also necessary[0]. The same reasoning, applied to the not-insignificant portions of the population with more severe disabilities than color-blindness, would condemn very nearly every tool in the history of technological civilization. 0: And in this case - as you yourself have pointed out - happily available.
- vyrotek 6y agoMicrosoft's new Terminal is really customizable https://devblogs.microsoft.com/commandline/windows-terminal-1-0/ https://devblogs.microsoft.com/commandline/windows-terminal-...
- digisign 6y agoWelcome to the 80s & 90s. :D
- WorldMaker 6y agoBetter late than never. :)