2024-05-05 20:02:10 +01:00
#!/usr/bin/env bash
2023-12-14 12:11:19 +00:00
# SPDX-License-Identifier: MIT
2023-12-21 14:17:18 +00:00
# This script checks consistency between the filenames and the page title.
# Usage: ./scripts/wrong-filename.sh
# Output file for recording inconsistencies
2023-12-21 17:50:46 +00:00
OUTPUT_FILE = "inconsistent-filenames.txt"
2023-12-21 14:17:18 +00:00
# Remove existing output file (if any)
rm -f " $OUTPUT_FILE "
2024-05-27 18:38:56 +01:00
touch " $OUTPUT_FILE "
2023-12-21 14:17:18 +00:00
2024-05-27 18:38:56 +01:00
IGNORE_LIST = ( "exclamation mark" "caret" "history expansion" "qm move disk" "umount" "rename" )
2024-05-05 20:02:10 +01:00
2023-12-14 12:11:19 +00:00
set -e
2023-12-21 14:17:18 +00:00
# Iterate through all Markdown files in the 'pages' directories
2023-12-21 15:44:35 +00:00
find pages* -name '*.md' -type f | while read -r path; do
2023-12-21 14:17:18 +00:00
# Extract the expected command name from the filename
2024-05-05 20:02:10 +01:00
COMMAND_NAME_FILE = $( basename " $path " | head -c-4 | sed 's/nix3/nix/' | sed 's/\.fish//' | sed 's/\.js//' | sed 's/\.1//' | tr '-' ' ' | tr '[:upper:]' '[:lower:]' )
2023-12-21 14:17:18 +00:00
# Extract the command name from the first line of the Markdown file
2024-05-05 21:09:10 +01:00
COMMAND_NAME_PAGE = $( head -n1 " $path " | tail -c+3 | sed 's/--//' | tr '-' ' ' | tr '[:upper:]' '[:lower:]' )
2023-12-21 14:17:18 +00:00
# Check if there is a mismatch between filename and content command names
2024-05-05 20:02:10 +01:00
if [ [ " $COMMAND_NAME_FILE " != " $COMMAND_NAME_PAGE " && ! ${ IGNORE_LIST [*] } = ~ $COMMAND_NAME_PAGE ] ] ; then
2023-12-21 14:17:18 +00:00
echo " Inconsistency found in file: $path : $COMMAND_NAME_PAGE should be $COMMAND_NAME_FILE " >> " $OUTPUT_FILE "
2023-12-14 12:11:19 +00:00
fi
done