Skip to content

Instantly share code, notes, and snippets.

@TravonteD
Created September 18, 2025 18:22
Show Gist options
  • Select an option

  • Save TravonteD/51cdf4ad1044ae449983126bf87b2886 to your computer and use it in GitHub Desktop.

Select an option

Save TravonteD/51cdf4ad1044ae449983126bf87b2886 to your computer and use it in GitHub Desktop.
A small go program to add progress bars to any (non-interactive) command
package main
import (
"fmt"
"os"
"os/exec"
"sync"
"time"
)
// Displays a progress bar until the given command completes
// Uses the ConEmu OSC 9;4 protocol to do this
// Known support Ghostty 1.2+
func main() {
args := os.Args[1:]
cmdName := args[0]
progressSequence := "\u001b]9;4;3;;\a"
stopSequence := "\u001b]9;4;0;;\a"
go func() {
for {
fmt.Print(progressSequence)
time.Sleep(100 * time.Millisecond)
}
}()
var wg sync.WaitGroup
wg.Go(func() {
cmd := exec.Command(cmdName, args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Println(err.Error())
}
})
wg.Wait()
fmt.Print(stopSequence)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment