experiments in a post-browser web
at main 28 lines 616 B view raw
1#!/bin/bash 2# Wrapper script that times any command and shows duration at the end 3# Usage: ./scripts/timed.sh <command> [args...] 4# 5# Example: ./scripts/timed.sh yarn build 6# Output: [command output] 7# ⏱ 2.34s 8 9start=$(date +%s.%N) 10 11# Run the command 12"$@" 13exit_code=$? 14 15end=$(date +%s.%N) 16 17# Calculate duration (using bc for floating point, with fallback) 18if command -v bc &> /dev/null; then 19 duration=$(echo "$end - $start" | bc) 20else 21 # Fallback to integer seconds if bc not available 22 duration=$((${end%.*} - ${start%.*})) 23fi 24 25# Format output nicely 26printf '\n⏱ %ss\n' "$duration" 27 28exit $exit_code