-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathwrong-filename.sh
executable file
·29 lines (22 loc) · 1.36 KB
/
wrong-filename.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# This script checks consistency between the filenames and the page title.
# Usage: ./scripts/wrong-filename.sh
# Output file for recording inconsistencies
OUTPUT_FILE="inconsistent-filenames.txt"
# Remove existing output file (if any)
rm -f "$OUTPUT_FILE"
touch "$OUTPUT_FILE"
IGNORE_LIST=("caret" "curly brace" "dollar sign" "dot" "exclamation mark" "tilde" "percent sign" "qm move disk" "umount" "rename" "pacman d" "pacman f" "pacman q" "pacman r" "pacman s" "pacman t" "pacman u" "parted")
set -e
# Iterate through all Markdown files in the 'pages' directories
find pages* -name '*.md' -type f | while read -r path; do
# Extract the expected command name from the filename
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:]')
# Extract the command name from the first line of the Markdown file
COMMAND_NAME_PAGE=$(head -n1 "$path" | tail -c+3 | sed 's/--//' | tr '-' ' ' | tr '[:upper:]' '[:lower:]')
# Check if there is a mismatch between filename and content command names
if [[ "$COMMAND_NAME_FILE" != "$COMMAND_NAME_PAGE" && ! ${IGNORE_LIST[*]} =~ $COMMAND_NAME_PAGE ]]; then
echo "Inconsistency found in file: $path: $COMMAND_NAME_PAGE should be $COMMAND_NAME_FILE" >> "$OUTPUT_FILE"
fi
done