Skip to content

Instantly share code, notes, and snippets.

@macmichael01
Last active February 14, 2025 20:24
Show Gist options
  • Save macmichael01/5e2b4ca39d5cd64dabb4718d761e3750 to your computer and use it in GitHub Desktop.
Save macmichael01/5e2b4ca39d5cd64dabb4718d761e3750 to your computer and use it in GitHub Desktop.
#!/bin/bash
# A simple script that makes use of pandoc for converting files between formats.
# Toss this file into a directory to process multiple files at once.
# args --ext <extension to look for> --to <extension to convert to>
# default ext is markdown default to is docx
# Ensure that you have pandoc installed located here: https://pandoc.org/installing.html
ext="md"
to="docx"
# Parse the command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--ext)
ext="$2" # Store the value of --ext
shift 2 # Move past the --ext and its value
;;
--to)
to="$2" # Store the value of --to
shift 2 # Move past the --to and its value
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done
directory_path="$(pwd)"
IFS=$'\n' md_files=($(find "$directory_path" -type f -name "*.${ext}"))
for file in "${md_files[@]}"; do
file_name=$(basename "$file" ".${ext}")
dir_name=$(dirname "$file")
echo ${dir_name}/${file_name}
pandoc "${file}" -o "${dir_name}/${file_name}.${to}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment