Skip to content

Instantly share code, notes, and snippets.

View isurfer21's full-sized avatar

Abhishek Kumar isurfer21

View GitHub Profile
@isurfer21
isurfer21 / gen-video-list.ts
Created December 4, 2025 16:17
A CLI tool to generate video list for a given directory to be used with FFmpeg app.
#!/usr/bin/env bun
import { readdir, writeFile, stat } from 'fs/promises';
import { resolve, join, extname } from 'path';
// Define common video file extensions (lowercase)
const VIDEO_EXTENSIONS = new Set([
'.mp4', '.mkv', '.avi', '.mov', '.wmv', '.flv', '.webm', '.m4v', '.3gp'
]);
@isurfer21
isurfer21 / sync-dir.sh
Created November 30, 2025 07:15
Shell script to synchronize source directory to target directory on external hard disk
#!/bin/zsh
# Script to synchronize source directory to target directory on external hard disk
# Default: one-way sync without deleting files on target.
# Options:
# -d, --dry → Simulate deletions (dry-run with --delete)
# -x, --prune → Perform actual deletions (--delete)
# -h, --help → Show help menu
show_help() {
@isurfer21
isurfer21 / node_modules_age.sh
Last active August 5, 2025 05:33
A CLI tool which calculates the age of the node_modules directory in days.
#!/bin/bash
# Define the path to the node_modules directory
NODE_MODULES_DIR="node_modules"
# Check if node_modules directory exists
if [ ! -d "$NODE_MODULES_DIR" ]; then
echo "node_modules directory does not exist."
else
# Get the last modified time of the most recently modified file in node_modules
@isurfer21
isurfer21 / generate_ssh_key.sh
Created July 15, 2025 04:02
Here's a simple Bash script that generates an SSH key pair (if one doesn't already exist) and displays the public key so you can copy it to a remote system for SSH access:
#!/bin/bash
# Set the key file path
KEY_PATH="$HOME/.ssh/id_rsa"
# Check if the SSH key already exists
if [ -f "$KEY_PATH.pub" ]; then
echo "SSH key already exists at $KEY_PATH.pub"
else
echo "Generating a new SSH key..."
@isurfer21
isurfer21 / concatenate-files.sh
Last active July 3, 2025 09:03
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 relative path from given absoule path & base path
get_relative_path() {
local absolute_path="$1"
local base_path="$2"
# Remove trailing slashes for consistency
absolute_path="${absolute_path%/}"
base_path="${base_path%/}"
@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