-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathconvert_to_includes.sh
executable file
·34 lines (26 loc) · 1.08 KB
/
convert_to_includes.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
30
31
32
33
34
#!/usr/bin/env bash
set -euo pipefail
# Resolve the directory of this script as PROJECT_ROOT
PROJECT_ROOT="$(dirname "$(realpath "$0")")"
# Prompt the user for the filename to move
echo "Which file do you want to move?"
read -r FILE_TO_MOVE
move_file() {
local file_to_move="$1"
# Find all occurrences of the file in the 'platforms' directory
while IFS= read -r -d '' found_file; do
# Strip the leading path to _docs/_developer_guide/ to get the relative path
local relative_path="${found_file#"$PROJECT_ROOT/_docs/_developer_guide/"}"
# Construct the destination file path
local dest_file="$PROJECT_ROOT/_includes/developer_guide/$relative_path"
local dest_dir
dest_dir="$(dirname "$dest_file")"
# Create the destination directory if it doesn't exist
mkdir -p "$dest_dir"
# Copy the file
cp "$found_file" "$dest_file"
echo "Copied $found_file -> $dest_file"
done < <(find "$PROJECT_ROOT/_docs/_developer_guide/platforms" -type f -name "$file_to_move" -print0)
}
# Execute the function with the user-specified filename
move_file "$FILE_TO_MOVE"