Skip to content

Instantly share code, notes, and snippets.

View isurfer21's full-sized avatar

Abhishek Kumar isurfer21

View GitHub Profile
@isurfer21
isurfer21 / concatenate-files.sh
Last active June 11, 2025 12:25
Here's a Bash script that recursively traverses a directory, reads each file, and concatenates them into a single output file. It adds a comment at the top of each file's content using the appropriate syntax based on the file extension.
#!/bin/bash
# Function to get directory name from path
get_dirname() {
local input_path="$1"
local resolved_path
# Check if realpath exists
if command -v realpath >/dev/null 2>&1; then
# Try to resolve the path fully
@isurfer21
isurfer21 / concatenate_files_to_markdown.sh
Last active May 21, 2025 08:27
Created a bash script to concatenate all the files in the directory and their sub-directories (of source code) along with their filename into single consolidated file in markdown format persisting file type
#!/bin/bash
# Script to concatenate all files in a directory and its subdirectories
# into a single markdown file with filenames and content preserved.
# Usage: ./concatenate_files_to_markdown.sh [source_directory] [output_file.md]
# Defaults: source_directory = current directory, output_file.md = consolidated.md
SOURCE_DIR="${1:-.}"
OUTPUT_FILE="${2:-consolidated.md}"
@isurfer21
isurfer21 / merge-pdfs.sh
Created November 19, 2024 13:05
Here is a Bash script that takes command line arguments for the source PDF files and the output merged PDF file. The script uses Ghostscript (gs) to merge the specified PDF files.
#!/bin/bash
# Check if at least two arguments are provided (at least one source and one output)
if [ "$#" -lt 2 ]; then
echo "Usage: ${0##*/} output.pdf source1.pdf [source2.pdf ... sourceN.pdf]"
exit 1
fi
# The first argument is the output file
output_file="$1"
@isurfer21
isurfer21 / png2jpg.sh
Created October 24, 2024 16:06
ImageMagick based command-line utility shell script to convert `png` to `jpg` with white background if having transparent background by default
#!/bin/bash
# Function to print help message
function print_help() {
app_name=${0##*/}
echo "Syntax: $app_name <input_image> <output_image>"
echo " -h: Display this help message"
echo "Usage: "
echo " $app_name input.png output.jpg"
echo " $app_name '*.png' output.jpg"
@isurfer21
isurfer21 / rust.sh
Created July 19, 2024 03:16
A bash script expects rust filename then compiles, executes & deletes binary to automate the process
#!/bin/bash
HELP_MENU="Usage: ${0##*/} [-h|--help] <rust_filename>
Compile and run a Rust file, then delete the binary.
Options:
-h, --help Show this help menu
"
if [ $# -eq 0 ]; then
@isurfer21
isurfer21 / copy-file.sh
Last active July 3, 2024 06:17
A CLI tool is a bash script that creates multiple copies of a specified file, renaming each copy with an incrementing number.
#!/bin/bash
# Check if the required arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: ${0##*/} <file-path> <copy-count>"
exit 1
fi
# Assign the arguments to variables
file_path=$1
@isurfer21
isurfer21 / gen-uml.sh
Created April 17, 2024 14:10
Wrapper to generate UML from TypeScript files using TsUML2 (npm i -g tsuml2) to output an image file with the same filename as the input file.
#!/usr/bin/env bash
if [[ $# -gt 0 ]]
then
filename=$1
tsuml2 --glob $filename -m -o $filename.svg
else
echo "Error: arguments missing!"
echo "Syntax: uml <filename>"
fi
@isurfer21
isurfer21 / fit-in.js
Created March 1, 2024 16:32
A custom function in EcmaScript to insert the template literals (variables) in the given template string using tagged template. It is helpful in keeping all the templates separately.
function fitIn(template, ...values) {
// console.log(template, values);
let result = [];
for (let i = 0; i < template.length; i++) {
result.push(template[i]);
if (i < values.length) {
result.push(values[i]);
}
}
return result.join("");
@isurfer21
isurfer21 / md2htm.js
Last active March 6, 2024 06:26
The md2htm is a CLI utility that converts markdown to HTML using bun & pandoc
#!/usr/bin/env bun
import { parseArgs } from "node:util";
const VERSION = '1.0.0';
const { values, positionals } = parseArgs({
args: Bun.argv,
options: {
file: {
type: "string",
@isurfer21
isurfer21 / pdf2png.sh
Last active January 9, 2024 04:52
PDF to PNG converter CLI wrapper made using Imagemagick
#!/bin/bash
# This script takes two arguments: input filename and output filename
# It uses imagemagick to convert the input file to a png file with specified options
# Check if the number of arguments is correct
if [ $# -ne 2 ]; then
app_name=${0##*/}
echo "Syntax: $app_name <input> <output>"
echo "Usage: "