Skip to content

Instantly share code, notes, and snippets.

@nmdra
Created February 20, 2023 06:15
Show Gist options
  • Save nmdra/b56405153a1193c7f5bd9ad5331c9259 to your computer and use it in GitHub Desktop.
Save nmdra/b56405153a1193c7f5bd9ad5331c9259 to your computer and use it in GitHub Desktop.
Simple Bash script for Compile & Run C programs
#!/bin/bash
# Simple Script for Compile & Run C programs
# Shellcheck Passed.
# Contributors: nimendra
# Last Update: 2023-02-20 11:04
# github.com/nmdra
# twitter.com/nimendra_
# Installations👇
# Dependencies: fd, fzf, gcc,
# mv ccc ./local/bin && chmod +x ccc
# --------------------------------------------
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NOCOLOR='\033[0m'
# Choosing .c file with Fzf
choose="$(fd -d 1 -e c | fzf --cycle --reverse)" &&
cc "$choose" -o "$choose%.*" && # Compile C program with Gcc
echo -e "👇$choose ${GREEN}Compiled successfully.✅${NOCOLOR}\n" &&
# Run Compiled Program
if test -f "$choose%.*"; then
./"$choose%.*" && rm "$choose%.*" # Run program & Remove Compiled program
else
echo -e "${RED}Program doesn't exist 🤯${NOCOLOR}"
fi
# $choose%.* for Remove .c extesion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment