2024-05-05 21:02:10 +02:00
#!/usr/bin/env bash
2023-12-14 13:11:19 +01:00
# SPDX-License-Identifier: MIT
2023-12-21 19:47:18 +05:30
# This script checks consistency between the filenames and the page title.
# Usage: ./scripts/wrong-filename.sh
# Output file for recording inconsistencies
2023-12-21 23:20:46 +05:30
OUTPUT_FILE = "inconsistent-filenames.txt"
2023-12-21 19:47:18 +05:30
# Remove existing output file (if any)
rm -f " $OUTPUT_FILE "
2024-05-27 19:38:56 +02:00
touch " $OUTPUT_FILE "
2023-12-21 19:47:18 +05:30
2025-02-19 18:31:18 +01:00
IGNORE_LIST = ( "caret" "curly brace" "dollar sign" "dot" "exclamation mark" "tilde" "percent sign" "history expansion" "qm move disk" "umount" "rename" "pacman d" "pacman f" "pacman q" "pacman r" "pacman s" "pacman t" "pacman u" "parted" )
2024-05-05 21:02:10 +02:00
2023-12-14 13:11:19 +01:00
set -e
2023-12-21 19:47:18 +05:30
# Iterate through all Markdown files in the 'pages' directories
2023-12-21 21:14:35 +05:30
find pages* -name '*.md' -type f | while read -r path; do
2023-12-21 19:47:18 +05:30
# Extract the expected command name from the filename
2024-05-05 21:02:10 +02: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 19:47:18 +05:30
# Extract the command name from the first line of the Markdown file
2024-05-05 22:09:10 +02:00
COMMAND_NAME_PAGE = $( head -n1 " $path " | tail -c+3 | sed 's/--//' | tr '-' ' ' | tr '[:upper:]' '[:lower:]' )
2023-12-21 19:47:18 +05:30
# Check if there is a mismatch between filename and content command names
2024-05-05 21:02:10 +02:00
if [ [ " $COMMAND_NAME_FILE " != " $COMMAND_NAME_PAGE " && ! ${ IGNORE_LIST [*] } = ~ $COMMAND_NAME_PAGE ] ] ; then
2023-12-21 19:47:18 +05:30
echo " Inconsistency found in file: $path : $COMMAND_NAME_PAGE should be $COMMAND_NAME_FILE " >> " $OUTPUT_FILE "
2023-12-14 13:11:19 +01:00
fi
done