Skip to content

Instantly share code, notes, and snippets.

@do-me
Last active July 9, 2024 12:50
Show Gist options
  • Save do-me/3c88749ce5a3f19bf9fd1031ff317c52 to your computer and use it in GitHub Desktop.
Save do-me/3c88749ce5a3f19bf9fd1031ff317c52 to your computer and use it in GitHub Desktop.
Shell command to get all untracked markdown files in a git repo in mkdocs format
# What's this good for? If you're batch editing/creating new markdown files for
# mkdocs and need to add the entries in the mkdocs.yml file
git ls-files --others --exclude-standard '*.md' | grep '\.md$' | while read filename; do
echo "- $(basename "${filename%.*}" | sed 's/^[[:space:]]*//'): $(basename "$filename")"
done
# Output
# - copernicus_service_provider: copernicus_service_provider.md
# - expanded_uncertainty: expanded_uncertainty.md
# - standard_uncertainty: standard_uncertainty.md
# If you need capitalization use this instead
git ls-files --others --exclude-standard '*.md' | grep '\.md$' | while read filename; do
title=$(basename "${filename%.*}")
title_with_spaces=$(echo "$title" | tr '_' ' ')
capitalized_title=$(echo "$title_with_spaces" | awk '{for(i=1;i<=NF;i++){$i=toupper(substr($i,1,1)) substr($i,2)}}1')
echo "- $capitalized_title: $(basename "$filename")"
done
# Output
# - Copernicus Service Provider: copernicus_service_provider.md
# - Expanded Uncertainty: expanded_uncertainty.md
# - Standard Uncertainty: standard_uncertainty.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment