citadel

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

fmtsafe (244B)


      1 #!/usr/bin/env bash
      2 
      3 cmd="$1"
      4 shift
      5 
      6 orig=$(mktemp)
      7 fmt=$(mktemp)
      8 
      9 function cleanup() {
     10 	rm -f "$orig" "$fmt"
     11 }
     12 
     13 trap cleanup exit
     14 
     15 cat > "$orig"
     16 
     17 <"$orig" $cmd "$@" > "$fmt" 2>/dev/null
     18 
     19 if [ $? -eq 0 ]; then
     20 	cat "$fmt"
     21 else
     22 	cat "$orig"
     23 fi
     24