Skip to content

Commit

Permalink
Remove carriage return on scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
coelacant1 committed Jan 10, 2025
1 parent 7dd0e17 commit 949e33d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
54 changes: 54 additions & 0 deletions .check/ConvertLineEndings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

import os
import sys

def convert_line_endings_to_unix(directory):
"""
Walk through the given directory (recursively), converting
Windows-style line endings (\r\n) to Unix-style (\n), except
in any directory named '.github'.
"""
for root, dirs, files in os.walk(directory):
# Skip the .github directory (and its subfolders if any)
if ".github" in dirs:
dirs.remove(".github")

for filename in files:
file_path = os.path.join(root, filename)
try:
# Read file in binary mode to see raw bytes
with open(file_path, "rb") as f:
content = f.read()
except OSError as e:
print(f"[ERROR] Could not open {file_path}: {e}")
continue

# Replace CRLF with LF
new_content = content.replace(b"\r\n", b"\n")

# Only write if there's a difference
if new_content != content:
try:
with open(file_path, "wb") as f:
f.write(new_content)
print(f"[INFO] Converted line endings in {file_path}")
except OSError as e:
print(f"[ERROR] Could not write to {file_path}: {e}")


def main():
if len(sys.argv) != 2:
print("Usage: python convert_line_endings.py <directory>")
sys.exit(1)

directory = sys.argv[1]

if not os.path.isdir(directory):
print(f"Error: {directory} is not a valid directory.")
sys.exit(1)

convert_line_endings_to_unix(directory)

if __name__ == "__main__":
main()
Binary file modified .site/SingleLineCommand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions CCPVEOffline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,20 @@ run_script() {
# Capture script output in an array, to truncate if needed
declare -a output_lines
if [ -x "$script_path" ]; then
mapfile -t output_lines < <("$script_path" "${param_array[@]}")
mapfile -t output_lines < <(
bash -c "
source \"./Utilities/Utilities.sh\"
exec \"${script_path}\" \"${param_array[@]}\"
"
)

else
mapfile -t output_lines < <(bash "$script_path" "${param_array[@]}")
mapfile -t output_lines < <(
bash -c "
source \"./Utilities/Utilities.sh\"
exec bash \"${script_path}\" \"${param_array[@]}\"
"
)
fi

LAST_SCRIPT="$(display_path "$script_path")"
Expand Down

0 comments on commit 949e33d

Please sign in to comment.