The timer_stop perform 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 just a few hours of looking out by way of examples.
Doing it in fish for people like me
That’s for bash after I’m ssh’d into certainly one of my Linux hosts, however I run fish on MacOS. I’ve a separate fish perform for getting the identical outcomes there, full with gross hacks for turning the measurement into human-readable kind. I made this code, and I’m unapologetic. Witness my cobbled-together StackOverflow-sourced kludge.
perform fish_prompt –description ‘Write out the immediate’
# Save the final standing
set -l last_status $standing
# Calculate the command period if out there
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 totally 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 period string
if take a look at $h -gt 0
set cmd_duration (string be a part of ” “(” $h “h” $m “m)”)
else if take a look at $m -gt 0
set cmd_duration (string be a part of ” “(” $m “m” $s “s)”)
else if take a look at $s -ge 10
set -l fraction (math “ground($ms / 100)”)
set cmd_duration (string be a part of ” “(” $s “.” $fraction “s)”)
else if take a look at $s -gt 0
set cmd_duration (string be a part of ” “(” $s “.” (printf “%03d” $ms) “s)”)
else if take a look at $ms -ge 100
set cmd_duration (string be a part of ” “(” $ms “ms)”)
else if take a look at $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 pink (set_color pink)
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 take a look at $last_status -eq 0
echo -n -s $inexperienced $checkmark
else
echo -n -s $pink $cross
finish
# Truly echo the period
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 typical 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 may take my colourful shell instruments from my chilly, useless 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 out there and works with none extra configuration.
Nothing incorrect with a bit colour!
Lee Hutchinson
Nothing incorrect with a bit colour!
Lee Hutchinson
Nothing incorrect with a bit colour!
Lee Hutchinson
There’s a little bit of aliasing (which I hold 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 an enormous fan of creating my numbers human-readable, and the -h change is due to this fact utilized liberally.
(Do notice that wrapping instructions like ip in GRC can generally do bizarre issues in the event 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 notice 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 comfortable 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.

