The timer_stop function is essential not only for stopping timers but also for converting the elapsed time into a human-readable format. However, navigating its complexities can be challenging for non-developers. This functionality, as cobbled together by “Past Lee,” demonstrates the ingenuity involved in overcoming programming hurdles.
Doing it in Fish for Folks Like Me
While the initial examples may cater to Bash users logged into their Linux hosts, users on MacOS typically prefer the Fish shell. Lee Hutchinson has created a specific Fish function that yields similar results, employing crafty hacks to present time measurements legibly. The following function showcases this creative effort:
function fish_prompt --description 'Write out the prompt'
# Save the last status
set -l last_status $status
# Calculate the command duration if available
set -l cmd_duration ""
if set -q CMD_DURATION
# Convert milliseconds to microseconds for more precise comparison
set -l duration_us (math "$CMD_DURATION * 1000")
# Calculate different time units
set -l us (math "$duration_us % 1000")
set -l ms (math "floor($duration_us / 1000) % 1000")
set -l s (math "floor($duration_us / 1000000) % 60")
set -l m (math "floor($duration_us / 60000000) % 60")
set -l h (math "floor($duration_us / 3600000000)")
# Format duration string
if test $h -gt 0
set cmd_duration (string join '' "(" $h "h" $m "m)")
else if test $m -gt 0
set cmd_duration (string join '' "(" $m "m" $s "s)")
else if test $s -ge 10
set -l fraction (math "floor($ms / 100)")
set cmd_duration (string join '' "(" $s "." $fraction "s)")
else if test $s -gt 0
set cmd_duration (string join '' "(" $s "." (printf "%03d" $ms) "s)")
else if test $ms -ge 100
set cmd_duration (string join '' "(" $ms "ms)")
else if test $ms -gt 0
set -l fraction (math "floor($us / 100)")
set cmd_duration (string join '' "(" $ms "." $fraction "ms)")
else
set cmd_duration (string join '' "(" $us "us)")
end
end
# Define unicode symbols for status
set -l checkmark "✓"
set -l cross "✗"
# Colors
set -l normal (set_color normal)
set -l dark_gray (set_color 555555)
set -l blue (set_color -o blue)
set -l red (set_color red)
set -l green (set_color green)
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 status
# Status indicator with exit status
if test $last_status -eq 0
echo -n -s $green $checkmark
else
echo -n -s $red $cross
end
# Actually echo the duration
echo -n -s $dark_gray " $cmd_duration"
# Do the rest of the prompt
echo
set -l host_color $purple
echo -n -s $host_color $USER "@" (prompt_hostname) $normal ":" $blue (prompt_pwd) $normal " $ "
end
A Splash of Color
Having spent formative years captivated by ANSI BBS graphics, Lee has developed a fondness for colorful terminal text, distinguishing him from conventional system administrators. While some believe that syntax highlighting undermines comprehension, Lee argues otherwise, insisting that he benefits from a vibrant terminal environment.
To enhance the color experience, he leverages a program called GRC (Generic Colorizer), which effortlessly adds color to terminal outputs without requiring extensive configurations. The transformation from standard text to a riot of colors can be visually striking:
Nothing wrong with a little color!
Lee Hutchinson
Nothing wrong with a little color!
Lee Hutchinson
To integrate colorful output into his workflow, Lee implements aliasing in his .bash_aliases file:
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'By applying the -h switch, he ensures human readability across various outputs. However, he wisely advises caution when using GRC with certain commands that may produce confusing results when piped.
The Terminal Itself
Readers may also notice that Lee prefers MacOS’s Terminal.app despite the myriad of alternatives. His comfort with this application continues to outweigh the potential benefits of exploring contenders like Ghostty, Alacritty, and iTerm2. This highlights a common trend among users who appreciate familiarity over exploration, even in a rapidly evolving tech landscape.
You can read more about Lee’s terminal setups and colorful experiences here.
Image Credit: arstechnica.com







