Skip to content

Instantly share code, notes, and snippets.

@rapiz1
Created February 18, 2021 14:22
Show Gist options
  • Save rapiz1/86cca1edd6d2a7d96b3ac32ea4629e00 to your computer and use it in GitHub Desktop.
Save rapiz1/86cca1edd6d2a7d96b3ac32ea4629e00 to your computer and use it in GitHub Desktop.
Fish script to compile and run c program like go run
# Compile and run c program, just like `go run`
# Usage: crun hello.c
# Put this to ~/.config/fish/config.fish, or create a file in ~/.config/fish/functions/
function crun
set prog $argv[1]
set exec (mktemp)
if gcc $prog -o $exec
set_color brgreen
echo -e Compilation success. Running...\n
set_color normal
else
set_color -o red
echo Compilation failed.
return
end
if $exec
set_color brgrey
echo -e \nProgram exited normally.
else
set prog_status $status
set_color -o red
echo -e \nProgram exited with status code $prog_status.
end
rm $exec
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment