aboutsummaryrefslogtreecommitdiff
path: root/scripts/.scripts/latex_template.sh
diff options
context:
space:
mode:
authoromagdy <omar.professional8777@gmail.com>2024-11-18 22:59:00 +0200
committeromagdy <omar.professional8777@gmail.com>2024-11-18 22:59:00 +0200
commitda805b1ecdd1963f490a747670460e97474e1eb8 (patch)
tree6c1ec95aea35393355a6996375648fdf185ff68d /scripts/.scripts/latex_template.sh
parent750e399f5f1ddfdafbe50c49c5257b2de8a5e08c (diff)
downloaddotfiles-da805b1ecdd1963f490a747670460e97474e1eb8.tar.xz
dotfiles-da805b1ecdd1963f490a747670460e97474e1eb8.zip
Nothing worth mentioning
Diffstat (limited to 'scripts/.scripts/latex_template.sh')
-rwxr-xr-xscripts/.scripts/latex_template.sh120
1 files changed, 60 insertions, 60 deletions
diff --git a/scripts/.scripts/latex_template.sh b/scripts/.scripts/latex_template.sh
index 03054e3..2826fd9 100755
--- a/scripts/.scripts/latex_template.sh
+++ b/scripts/.scripts/latex_template.sh
@@ -1,85 +1,85 @@
#!/bin/bash
-templates_dir="/run/media/omar/Storage/omar/Latex Templates"
-logo="/run/media/omar/Storage/omar/College/logo.png"
-json_file="/run/media/omar/Storage/omar/College/Courses Templates/Spring2024.json"
+templates_dir="/mnt/Storage/omar/Latex Templates"
+logo="/mnt/Storage/omar/College/logo.png"
+json_file="/mnt/Storage/omar/College/Courses Templates/Fall2024.json"
# List of template options
templates=("lab_report" "general_report")
# Function to replace placeholders in a template file
replace_placeholders() {
- # Check if a template file is provided
- if [ -z "$1" ]; then
- echo "Usage: replace_placeholders <template_file>"
- return 1
- fi
-
- # Check if the provided file exists
- if [ ! -f "$1" ]; then
- echo "File '$1' not found."
- return 1
- fi
-
- # Read the template file content
- template_content=$(<"$1")
-
- # Extract course names from JSON and load them into an array
- IFS=$'\n' courses=($(jq -r '.[] | .course_title' "$json_file"))
-
- # Display course names and ask user to select
- echo "Select the course:"
- for i in "${!courses[@]}"; do
- echo "$((i + 1)). ${courses[i]}"
- done
- read -p "Enter the number of the course you want to use: " course_choice
-
- # Validate selection
- if ! [[ "$course_choice" =~ ^[0-9]+$ ]] || ((course_choice < 1 || course_choice > ${#courses[@]})); then
- echo "Invalid input. Please enter a number within the range."
- return 1
- fi
-
- # Get the selected course JSON object
- matched_json=$(jq -r --argjson idx $((course_choice - 1)) '.[$idx]' "$json_file")
-
- # Decode the JSON and replace placeholders
- course_title=$(echo "$matched_json" | jq -r '.course_title')
- course_code=$(echo "$matched_json" | jq -r '.course_code')
- instructor=$(echo "$matched_json" | jq -r '.instructor')
- teaching_assistant=$(echo "$matched_json" | jq -r '.teaching_assistant')
-
- # Replace each field in the template
- template_content=$(echo "$template_content" | sed "s/<course_title>/$course_title/g")
- template_content=$(echo "$template_content" | sed "s/<course_code>/$course_code/g")
- template_content=$(echo "$template_content" | sed "s/<instructor>/$instructor/g")
- template_content=$(echo "$template_content" | sed "s/<teaching_assistant>/$teaching_assistant/g")
-
- cp "$logo" .
- read -p "Enter name for your file: " file_name
-
- # Write the modified content to a new file
- echo "$template_content" >"./$file_name"
- echo "Replacement completed. Modified file saved as '$file_name'."
+ # Check if a template file is provided
+ if [ -z "$1" ]; then
+ echo "Usage: replace_placeholders <template_file>"
+ return 1
+ fi
+
+ # Check if the provided file exists
+ if [ ! -f "$1" ]; then
+ echo "File '$1' not found."
+ return 1
+ fi
+
+ # Read the template file content
+ template_content=$(<"$1")
+
+ # Extract course names from JSON and load them into an array
+ IFS=$'\n' courses=($(jq -r '.[] | .course_title' "$json_file"))
+
+ # Display course names and ask user to select
+ echo "Select the course:"
+ for i in "${!courses[@]}"; do
+ echo "$((i + 1)). ${courses[i]}"
+ done
+ read -p "Enter the number of the course you want to use: " course_choice
+
+ # Validate selection
+ if ! [[ "$course_choice" =~ ^[0-9]+$ ]] || ((course_choice < 1 || course_choice > ${#courses[@]})); then
+ echo "Invalid input. Please enter a number within the range."
+ return 1
+ fi
+
+ # Get the selected course JSON object
+ matched_json=$(jq -r --argjson idx $((course_choice - 1)) '.[$idx]' "$json_file")
+
+ # Decode the JSON and replace placeholders
+ course_title=$(echo "$matched_json" | jq -r '.course_title')
+ course_code=$(echo "$matched_json" | jq -r '.course_code')
+ instructor=$(echo "$matched_json" | jq -r '.instructor')
+ teaching_assistant=$(echo "$matched_json" | jq -r '.teaching_assistant')
+
+ # Replace each field in the template
+ template_content=$(echo "$template_content" | sed "s/<course_title>/$course_title/g")
+ template_content=$(echo "$template_content" | sed "s/<course_code>/$course_code/g")
+ template_content=$(echo "$template_content" | sed "s/<instructor>/$instructor/g")
+ template_content=$(echo "$template_content" | sed "s/<teaching_assistant>/$teaching_assistant/g")
+
+ cp "$logo" .
+ read -p "Enter name for your file: " file_name
+
+ # Write the modified content to a new file
+ echo "$template_content" >"./$file_name"
+ echo "Replacement completed. Modified file saved as '$file_name'."
}
# Display template options to the user
echo "Choose a template:"
for ((i = 0; i < ${#templates[@]}; i++)); do
- echo "$((i + 1)). ${templates[i]}"
+ echo "$((i + 1)). ${templates[i]}"
done
# Read user input for template selection
read -p "Enter the number of the template you want to use: " choice
if ! [[ "$choice" =~ ^[0-9]+$ ]]; then
- echo "Invalid input. Please enter a number."
- exit 1
+ echo "Invalid input. Please enter a number."
+ exit 1
fi
if ((choice < 1 || choice > ${#templates[@]})); then
- echo "Invalid choice. Please enter a number within the range."
- exit 1
+ echo "Invalid choice. Please enter a number within the range."
+ exit 1
fi
selected_template=${templates[choice - 1]}