aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/.scripts/books.sh29
-rwxr-xr-xscripts/.scripts/latex_template.sh120
2 files changed, 84 insertions, 65 deletions
diff --git a/scripts/.scripts/books.sh b/scripts/.scripts/books.sh
index 307ec89..6c49d62 100755
--- a/scripts/.scripts/books.sh
+++ b/scripts/.scripts/books.sh
@@ -9,14 +9,33 @@
# #
##################################################################
-path="/run/media/omar/Storage/omar/Books"
-choice=$(ls -a "$path" | dmenu -i -l 10)
+# Set the path to the books directory
+path="/mnt/Storage/omar/Books/"
+
+# Detect whether we're in a Wayland or X11 session
+if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
+ # Wayland session - use wofi
+ launcher="wofi --dmenu -i -l 10"
+elif [ "$XDG_SESSION_TYPE" = "x11" ]; then
+ # X11 session - use dmenu
+ launcher="dmenu -i -l 10"
+else
+ echo "Error: Could not detect display server (Wayland or X11)."
+ exit 1
+fi
+
+# Initial directory to choose from
+choice=$(ls -a "$path" | $launcher)
+
+# Initialize the new choice as the first directory selected
new_choice=$choice
+# Loop through directories until a file is selected
while [ -d "$path/$new_choice" ]; do
- choice=$(ls -a "$path/$new_choice" | dmenu -i -l 10)
- new_choice+="/"
- new_choice+=$choice #path/books for cs/
+ # Recurse into the selected directory and show options again
+ choice=$(ls -a "$path/$new_choice" | $launcher)
+ new_choice+="/$choice" # Append the choice to the path
done
+# Open the selected file with zathura in fullscreen mode
zathura --mode fullscreen "$path/$new_choice"
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]}