79092648

Date: 2024-10-16 06:05:59
Score: 0.5
Natty:
Report link

How to automatically add file paths like comment?

Simply try to correct and refactor the code you provided currently.

#!/bin/bash

pwd=scripts/test_copy-content

files=$(find "$pwd" -type f)

for file in $files; do
    case "$file" in
        *.sh|Makefile)
            First-line_comment="# *$file"
            ;;
        *.go|*.py)
            First-line_comment="# *$file"
            ;;
        *.md|*.html)
            First-line_comment="<!-- *$file -->"
            ;;
        *.css|*.js)
            First-line_comment="/* *$file */"
            ;;
        *.ico|*.jpg|*.png)
            # Skip these file types
            continue
            ;;
        *)
            First-line_comment="# *$file"
            ;;
    esac

    firstline=$(head -n 1 "$file")

    if [[ "$firstline" != "$First-line_comment" ]]; then
        echo "$First-line_comment\n$(cat "$file")" > "$file"
    fi

done
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How to
  • Low reputation (0.5):
Posted by: Shelton Liu