Ars Asks: Share your shell and present us your tricked-out terminals!

0
terminal-hotness-1152x648.jpg


The timer_stop operate additionally has the job of changing the timer right into a human-readable format, and it’s in all probability messier than it must be. I’m no developer, although, so that is what Previous Lee settled on after a number of hours of looking out by means of examples.

Doing it in fish for folk like me

That’s for bash once I’m ssh’d into certainly one of my Linux hosts, however I run fish on MacOS. I’ve a separate fish operate for getting the identical outcomes there, full with gross hacks for turning the measurement into human-readable type. I made this code, and I’m unapologetic. Witness my cobbled-together StackOverflow-sourced kludge.

operate fish_prompt --description 'Write out the immediate'
    # Save the final standing
    set -l last_status $standing

    # Calculate the command length if accessible
    set -l cmd_duration ""
    if set -q CMD_DURATION
        # Convert milliseconds to microseconds for extra exact comparability
        set -l duration_us (math "$CMD_DURATION * 1000")

        # Calculate completely different time items
        set -l us (math "$duration_us % 1000")
        set -l ms (math "ground($duration_us / 1000) % 1000")
        set -l s (math "ground($duration_us / 1000000) % 60")
        set -l m (math "ground($duration_us / 60000000) % 60")
        set -l h (math "ground($duration_us / 3600000000)")

        # Format length string
        if check $h -gt 0
            set cmd_duration (string be a part of '' "(" $h "h" $m "m)")
        else if check $m -gt 0
            set cmd_duration (string be a part of '' "(" $m "m" $s "s)")
        else if check $s -ge 10
            set -l fraction (math "ground($ms / 100)")
            set cmd_duration (string be a part of '' "(" $s "." $fraction "s)")
        else if check $s -gt 0
            set cmd_duration (string be a part of '' "(" $s "." (printf "%03d" $ms) "s)")
        else if check $ms -ge 100
            set cmd_duration (string be a part of '' "(" $ms "ms)")
        else if check $ms -gt 0
            set -l fraction (math "ground($us / 100)")
            set cmd_duration (string be a part of '' "(" $ms "." $fraction "ms)")
        else
            set cmd_duration (string be a part of '' "(" $us "us)")
        finish
    finish

    # Outline unicode symbols for standing
    set -l checkmark "✓"
    set -l cross "✗"

    # Colours
    set -l regular (set_color regular)
    set -l dark_gray (set_color 555555)
    set -l blue (set_color -o blue)
    set -l crimson (set_color crimson)
    set -l inexperienced (set_color inexperienced)
    set -l purple (set_color -o purple)

    # First line
    echo # New line
    echo -n -s $dark_gray "["(date +%T)"] $last_status " # Time in brackets and exit standing

    # Standing indicator with exit standing
    if check $last_status -eq 0
        echo -n -s $inexperienced $checkmark
    else
        echo -n -s $crimson $cross
    finish

    # Truly echo the length
    echo -n -s $dark_gray " $cmd_duration"

    # Do the remainder of the immediate
    echo
    set -l host_color $purple
    echo -n -s $host_color $USER "@" (prompt_hostname) $regular ":" $blue (prompt_pwd) $regular " $ "
finish

A splash of colour

Spending my adolescence immersed in ANSI BBS graphics has in all probability made me a bit extra fond of colourful textual content in my terminal than the common frumpy, button-downed admin. Look, I do know some of us really feel that syntax highlighting and colours generally kill comprehension and encourage skimming, however what can I say? I really like them and depend on them. Maybe I skim an excessive amount of, however so be it. You possibly can take my colourful shell instruments from my chilly, lifeless palms.

To that finish, I lean on a bit program known as GRC (for Generic Colorizer) so as to add highlighting and coloration to different instruments. It’s broadly accessible and works with none further configuration.


Image showing the before and after of using GRC with ping

Nothing fallacious with a bit colour!

Lee Hutchinson

There’s a little bit of aliasing (which I preserve in .bash_aliases like a great citizen) to make colourful output the defaults on some frequent instructions:

    alias ls="ls --color=auto"
    alias ll="ls -AlFh --group-directories-first"
    alias df="grc df -h"
    alias du='grc du -h'
    alias free="grc free -h"
    alias ping='grc ping'
    alias traceroute="grc traceroute"
    alias ip='grc ip'

I’m additionally a giant fan of constructing my numbers human-readable, and the -h swap is subsequently utilized liberally.

(Do observe that wrapping instructions like ip in GRC can generally do bizarre issues in case you’re piping its output into one thing else. Use warning. Or don’t! It’s your pc, knock your self out!)

The terminal itself

Sharp-eyed readers will observe from the screenshots that I’m utilizing MacOS’s Terminal.app for my terminal program, regardless of there being much better choices. I suppose the excuse I’ve is that I’m cozy with Terminal.app and nothing has pulled me off of it. I’ve test-driven the standard suspects—Ghostty, Alacritty, the mighty iTerm2 with its superior tmux windowing integration, and even fancy new reinterpretations of the terminal expertise like Warp.

Leave a Reply

Your email address will not be published. Required fields are marked *