citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

gofmt-safe (185B)


      1 #!/usr/bin/env bash
      2 
      3 orig=$(mktemp)
      4 fmt=$(mktemp)
      5 
      6 cat > "$orig"
      7 
      8 <"$orig" gofmt "$@" > "$fmt" 2>/dev/null
      9 
     10 if [ $? -eq 0 ]; then
     11 	cat "$fmt"
     12 else
     13 	cat "$orig"
     14 fi
     15 
     16 rm -f "$orig" "$fmt"