generated from nhcarrigan/template
feat: rework scripts to be platform/user agnostic
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
Stores backups of all deleted configs.
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.backup/*
|
||||||
|
!.backup/.gitkeep
|
||||||
@@ -1,4 +1,84 @@
|
|||||||
#! /usr/bin/bash
|
#! /usr/bin/bash
|
||||||
|
|
||||||
rm -r match
|
# Color definitions
|
||||||
cp -r ~/.config/espanso/match .
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
MAGENTA='\033[0;35m'
|
||||||
|
BOLD='\033[1m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Prompt for username
|
||||||
|
echo -e "${CYAN}${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
echo -e "${CYAN}${BOLD} Espanso Config Pull${NC}"
|
||||||
|
echo -e "${CYAN}${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
echo ""
|
||||||
|
prompt_username="${YELLOW}Enter your system/account username: ${NC}"
|
||||||
|
read -p "$(printf '%b' "$prompt_username")" username
|
||||||
|
|
||||||
|
# Prompt for platform
|
||||||
|
echo ""
|
||||||
|
echo -e "${CYAN}${BOLD}Select the platform for your Espanso config:${NC}"
|
||||||
|
echo -e " ${GREEN}1)${NC} Linux: ${MAGENTA}/home/<user>/.config/espanso${NC}"
|
||||||
|
echo -e " ${GREEN}2)${NC} WSL: ${MAGENTA}/mnt/c/Users/<user>/AppData/Roaming/espanso${NC}"
|
||||||
|
echo -e " ${GREEN}3)${NC} Windows: ${MAGENTA}C:\\Users\\<user>\\AppData\\Roaming\\espanso${NC}"
|
||||||
|
echo -e " ${GREEN}4)${NC} Mac: ${MAGENTA}/Users/<user>/Library/Application Support/espanso${NC}"
|
||||||
|
echo -e " ${GREEN}5)${NC} Other (custom absolute path)"
|
||||||
|
echo ""
|
||||||
|
prompt_choice="${YELLOW}Enter your choice (1-5): ${NC}"
|
||||||
|
read -p "$(printf '%b' "$prompt_choice")" choice
|
||||||
|
|
||||||
|
# Build the path based on selection
|
||||||
|
case "$choice" in
|
||||||
|
1)
|
||||||
|
espanso_path="/home/$username/.config/espanso"
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
espanso_path="/mnt/c/Users/$username/AppData/Roaming/espanso"
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
espanso_path="/mnt/c/Users/$username/AppData/Roaming/espanso"
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
espanso_path="/Users/$username/Library/Application Support/espanso"
|
||||||
|
;;
|
||||||
|
5)
|
||||||
|
prompt_custom="${YELLOW}Enter the custom absolute path to espanso config: ${NC}"
|
||||||
|
read -p "$(printf '%b' "$prompt_custom")" espanso_path
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "${RED}${BOLD}✗ Invalid choice. Exiting.${NC}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Verify the path exists
|
||||||
|
if [ ! -d "$espanso_path" ]; then
|
||||||
|
echo -e "${RED}${BOLD}✗ Error: Path '$espanso_path' does not exist!${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify the match directory exists
|
||||||
|
if [ ! -d "$espanso_path/match" ]; then
|
||||||
|
echo -e "${RED}${BOLD}✗ Error: Match directory not found at '$espanso_path/match'!${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}${BOLD}→ Pulling from: ${CYAN}$espanso_path/match${NC}"
|
||||||
|
|
||||||
|
# Create backup of local match directory if it exists
|
||||||
|
if [ -d "match" ]; then
|
||||||
|
backup_date=$(date +%Y-%m-%d-%H%M%S)
|
||||||
|
backup_dir=".backup/${backup_date}-match"
|
||||||
|
echo -e "${YELLOW}${BOLD}→ Backing up local match directory to: ${CYAN}$backup_dir${NC}"
|
||||||
|
mkdir -p "$backup_dir"
|
||||||
|
cp -r match "$backup_dir/"
|
||||||
|
echo -e "${GREEN}${BOLD}✓ Backup created successfully${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf match
|
||||||
|
cp -r "$espanso_path/match" .
|
||||||
|
echo -e "${GREEN}${BOLD}✓ Done! Match directory pulled successfully.${NC}"
|
||||||
@@ -1,4 +1,96 @@
|
|||||||
#! /usr/bin/bash
|
#! /usr/bin/bash
|
||||||
|
|
||||||
rm -r /mnt/c/Users/accou/AppData/Roaming/espanso/match
|
# Color definitions
|
||||||
cp -r match /mnt/c/Users/accou/AppData/Roaming/espanso
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
CYAN='\033[0;36m'
|
||||||
|
MAGENTA='\033[0;35m'
|
||||||
|
BOLD='\033[1m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Verify local match directory exists
|
||||||
|
if [ ! -d "match" ]; then
|
||||||
|
echo -e "${RED}${BOLD}✗ Error: Local 'match' directory not found!${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Prompt for username
|
||||||
|
echo -e "${CYAN}${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
echo -e "${CYAN}${BOLD} Espanso Config Push${NC}"
|
||||||
|
echo -e "${CYAN}${BOLD}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||||||
|
echo ""
|
||||||
|
prompt_username="${YELLOW}Enter your system/account username: ${NC}"
|
||||||
|
read -p "$(printf '%b' "$prompt_username")" username
|
||||||
|
|
||||||
|
# Prompt for platform
|
||||||
|
echo ""
|
||||||
|
echo -e "${CYAN}${BOLD}Select the platform for your Espanso config:${NC}"
|
||||||
|
echo -e " ${GREEN}1)${NC} Linux: ${MAGENTA}/home/<user>/.config/espanso${NC}"
|
||||||
|
echo -e " ${GREEN}2)${NC} WSL: ${MAGENTA}/mnt/c/Users/<user>/AppData/Roaming/espanso${NC}"
|
||||||
|
echo -e " ${GREEN}3)${NC} Windows: ${MAGENTA}C:\\Users\\<user>\\AppData\\Roaming\\espanso${NC}"
|
||||||
|
echo -e " ${GREEN}4)${NC} Mac: ${MAGENTA}/Users/<user>/Library/Application Support/espanso${NC}"
|
||||||
|
echo -e " ${GREEN}5)${NC} Other (custom absolute path)"
|
||||||
|
echo ""
|
||||||
|
prompt_choice="${YELLOW}Enter your choice (1-5): ${NC}"
|
||||||
|
read -p "$(printf '%b' "$prompt_choice")" choice
|
||||||
|
|
||||||
|
# Build the path based on selection
|
||||||
|
case "$choice" in
|
||||||
|
1)
|
||||||
|
espanso_path="/home/$username/.config/espanso"
|
||||||
|
;;
|
||||||
|
2)
|
||||||
|
espanso_path="/mnt/c/Users/$username/AppData/Roaming/espanso"
|
||||||
|
;;
|
||||||
|
3)
|
||||||
|
espanso_path="/mnt/c/Users/$username/AppData/Roaming/espanso"
|
||||||
|
;;
|
||||||
|
4)
|
||||||
|
espanso_path="/Users/$username/Library/Application Support/espanso"
|
||||||
|
;;
|
||||||
|
5)
|
||||||
|
prompt_custom="${YELLOW}Enter the custom absolute path to espanso config: ${NC}"
|
||||||
|
read -p "$(printf '%b' "$prompt_custom")" espanso_path
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "${RED}${BOLD}✗ Invalid choice. Exiting.${NC}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Verify the espanso config directory exists, or ask to create it
|
||||||
|
if [ ! -d "$espanso_path" ]; then
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}${BOLD}⚠ Directory '$espanso_path' does not exist.${NC}"
|
||||||
|
prompt_create="${YELLOW}Would you like to create it? (y/n): ${NC}"
|
||||||
|
read -p "$(printf '%b' "$prompt_create")" create_dir
|
||||||
|
case "$create_dir" in
|
||||||
|
[Yy]|[Yy][Ee][Ss])
|
||||||
|
mkdir -p "$espanso_path"
|
||||||
|
echo -e "${GREEN}${BOLD}✓ Directory created successfully${NC}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo -e "${RED}${BOLD}✗ Cannot proceed without the directory. Exiting.${NC}"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}${BOLD}→ Pushing to: ${CYAN}$espanso_path${NC}"
|
||||||
|
|
||||||
|
# Create backup of remote match directory if it exists
|
||||||
|
if [ -d "$espanso_path/match" ]; then
|
||||||
|
backup_date=$(date +%Y-%m-%d-%H%M%S)
|
||||||
|
backup_dir=".backup/${backup_date}-match"
|
||||||
|
echo -e "${YELLOW}${BOLD}→ Backing up remote match directory to: ${CYAN}$backup_dir${NC}"
|
||||||
|
mkdir -p "$backup_dir"
|
||||||
|
cp -r "$espanso_path/match" "$backup_dir/"
|
||||||
|
echo -e "${GREEN}${BOLD}✓ Backup created successfully${NC}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "$espanso_path/match"
|
||||||
|
cp -r match "$espanso_path"
|
||||||
|
echo -e "${GREEN}${BOLD}✓ Done! Match directory pushed successfully.${NC}"
|
||||||
|
|||||||
@@ -1,88 +1,136 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Color definitions
|
||||||
|
RESET='\033[0m'
|
||||||
|
BOLD='\033[1m'
|
||||||
|
RED='\033[91m'
|
||||||
|
GREEN='\033[92m'
|
||||||
|
YELLOW='\033[93m'
|
||||||
|
BLUE='\033[94m'
|
||||||
|
MAGENTA='\033[95m'
|
||||||
|
CYAN='\033[96m'
|
||||||
|
|
||||||
# Directory containing YAML files
|
# Directory containing YAML files
|
||||||
MATCH_DIR="match"
|
MATCH_DIR="match"
|
||||||
|
|
||||||
# Check if directory exists
|
# Check if directory exists
|
||||||
if [ ! -d "$MATCH_DIR" ]; then
|
if [ ! -d "$MATCH_DIR" ]; then
|
||||||
echo "Error: Directory '$MATCH_DIR' not found!"
|
echo -e "${RED}${BOLD}Error:${RESET} ${RED}Directory '$MATCH_DIR' not found!${RESET}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Temporary file to store all triggers
|
# Temporary files to store triggers and replaces with metadata
|
||||||
ALL_TRIGGERS=$(mktemp)
|
# Format: trigger|replace|file|trigger_line|replace_line
|
||||||
ALL_REPLACES=$(mktemp)
|
ALL_TRIGGERS_DATA=$(mktemp)
|
||||||
|
ALL_REPLACES_DATA=$(mktemp)
|
||||||
|
|
||||||
# Find all YAML files and extract triggers
|
# Find all YAML files and extract triggers with their replace values and line numbers
|
||||||
echo "Scanning YAML files in $MATCH_DIR directory..."
|
echo -e "${CYAN}${BOLD}Scanning YAML files in $MATCH_DIR directory...${RESET}"
|
||||||
for file in "$MATCH_DIR"/*.y*ml; do
|
for file in "$MATCH_DIR"/*.y*ml; do
|
||||||
if [ -f "$file" ]; then
|
if [ -f "$file" ]; then
|
||||||
echo "Processing file: $(basename "$file")"
|
echo -e "${BLUE}Processing file:${RESET} ${BOLD}$(basename "$file")${RESET}"
|
||||||
# Extract triggers using grep and sed
|
# Process file line by line to track trigger-replace pairs
|
||||||
# This looks for lines with "trigger:" and captures the value
|
trigger_line=""
|
||||||
grep -E '^\s*-\s*trigger:' "$file" | sed 's/.*trigger:\s*"\([^"]*\)".*/\1/' >> "$ALL_TRIGGERS"
|
trigger_value=""
|
||||||
# Also extract replace values if they exist
|
replace_value=""
|
||||||
grep -E '^\s*replace:' "$file" | sed 's/.*replace:\s*"\([^"]*\)".*/\1/' >> "$ALL_REPLACES"
|
replace_line=""
|
||||||
|
line_num=0
|
||||||
|
|
||||||
|
while IFS= read -r line; do
|
||||||
|
line_num=$((line_num + 1))
|
||||||
|
|
||||||
|
# Check if this is a trigger line
|
||||||
|
if echo "$line" | grep -qE '^\s*-\s*trigger:'; then
|
||||||
|
trigger_line=$line_num
|
||||||
|
trigger_value=$(echo "$line" | sed 's/.*trigger:\s*"\([^"]*\)".*/\1/')
|
||||||
|
replace_value="" # Reset replace value for new trigger
|
||||||
|
replace_line="" # Reset replace line
|
||||||
|
# Check if this is a replace line (should be right after trigger)
|
||||||
|
elif echo "$line" | grep -qE '^\s*replace:'; then
|
||||||
|
replace_value=$(echo "$line" | sed 's/.*replace:\s*"\([^"]*\)".*/\1/')
|
||||||
|
replace_line=$line_num
|
||||||
|
# Save trigger data: trigger|replace|file|trigger_line|replace_line
|
||||||
|
if [ -n "$trigger_value" ]; then
|
||||||
|
echo "$trigger_value|$replace_value|$(basename "$file")|$trigger_line|$replace_line" >> "$ALL_TRIGGERS_DATA"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done < "$file"
|
||||||
else
|
else
|
||||||
echo "Warning: No YAML files found in $MATCH_DIR directory!"
|
echo -e "${YELLOW}${BOLD}Warning:${RESET} ${YELLOW}No YAML files found in $MATCH_DIR directory!${RESET}"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Also create a reverse mapping for replace values: replace|trigger|file|trigger_line|replace_line
|
||||||
|
awk -F'|' '{print $2"|"$1"|"$3"|"$4"|"$5}' "$ALL_TRIGGERS_DATA" > "$ALL_REPLACES_DATA"
|
||||||
|
|
||||||
# Check if we found any triggers
|
# Check if we found any triggers
|
||||||
if [ ! -s "$ALL_TRIGGERS" ]; then
|
if [ ! -s "$ALL_TRIGGERS_DATA" ]; then
|
||||||
echo "No triggers found in YAML files. Check file format or directory."
|
echo -e "${RED}${BOLD}Error:${RESET} ${RED}No triggers found in YAML files. Check file format or directory.${RESET}"
|
||||||
rm "$ALL_TRIGGERS"
|
rm "$ALL_TRIGGERS_DATA" "$ALL_REPLACES_DATA"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Extract just triggers to find duplicates
|
||||||
|
ALL_TRIGGERS=$(mktemp)
|
||||||
|
cut -d'|' -f1 "$ALL_TRIGGERS_DATA" > "$ALL_TRIGGERS"
|
||||||
|
|
||||||
# Sort triggers and find duplicates
|
# Sort triggers and find duplicates
|
||||||
echo -e "\nChecking for duplicate triggers..."
|
echo -e "\n${CYAN}${BOLD}Checking for duplicate triggers...${RESET}"
|
||||||
DUPLICATE_TRIGGERS=$(sort "$ALL_TRIGGERS" | uniq -d)
|
DUPLICATE_TRIGGERS=$(sort "$ALL_TRIGGERS" | uniq -d)
|
||||||
|
|
||||||
# Display results
|
# Display results
|
||||||
if [ -z "$DUPLICATE_TRIGGERS" ]; then
|
if [ -z "$DUPLICATE_TRIGGERS" ]; then
|
||||||
echo "Success: All triggers are unique!"
|
echo -e "${GREEN}${BOLD}✓ Success:${RESET} ${GREEN}All triggers are unique!${RESET}"
|
||||||
TOTAL=$(wc -l < "$ALL_TRIGGERS")
|
TOTAL=$(wc -l < "$ALL_TRIGGERS")
|
||||||
echo "Total number of triggers found: $TOTAL"
|
echo -e "${CYAN}Total number of triggers found:${RESET} ${BOLD}$TOTAL${RESET}"
|
||||||
else
|
else
|
||||||
echo "Error: Duplicate triggers found:"
|
echo -e "${RED}${BOLD}✗ Error:${RESET} ${RED}Duplicate triggers found:${RESET}"
|
||||||
echo "$DUPLICATE_TRIGGERS"
|
echo -e "${YELLOW}$DUPLICATE_TRIGGERS${RESET}"
|
||||||
|
|
||||||
# Optional: Show which files contain each duplicate
|
# Show detailed information for each duplicate
|
||||||
echo -e "\nDuplicates found in these files:"
|
echo -e "\n${CYAN}${BOLD}Detailed information for duplicates:${RESET}"
|
||||||
for dupe in $DUPLICATE_TRIGGERS; do
|
for dupe in $DUPLICATE_TRIGGERS; do
|
||||||
echo "Trigger \"$dupe\" found in:"
|
echo -e "\n${MAGENTA}${BOLD}Trigger${RESET} ${BOLD}\"$dupe\"${RESET} ${MAGENTA}found:${RESET}"
|
||||||
grep -l "trigger: \"$dupe\"" "$MATCH_DIR"/*.y*ml
|
grep "^$dupe|" "$ALL_TRIGGERS_DATA" | while IFS='|' read -r trigger replace file trigger_line replace_line; do
|
||||||
|
echo -e " ${YELLOW}→${RESET} Line ${MAGENTA}${BOLD}$trigger_line${RESET} in ${BLUE}$file${RESET}: ${CYAN}replace=${RESET}\"${GREEN}$replace${RESET}\""
|
||||||
|
done
|
||||||
done
|
done
|
||||||
|
rm "$ALL_TRIGGERS" "$ALL_TRIGGERS_DATA" "$ALL_REPLACES_DATA"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Extract just replace values to find duplicates
|
||||||
|
ALL_REPLACES=$(mktemp)
|
||||||
|
cut -d'|' -f1 "$ALL_REPLACES_DATA" > "$ALL_REPLACES"
|
||||||
|
|
||||||
# Sort replace values and find duplicates
|
# Sort replace values and find duplicates
|
||||||
echo -e "\nChecking for duplicate replace values..."
|
echo -e "\n${CYAN}${BOLD}Checking for duplicate replace values...${RESET}"
|
||||||
DUPLICATE_REPLACES=$(sort "$ALL_REPLACES" | uniq -d)
|
DUPLICATE_REPLACES=$(sort "$ALL_REPLACES" | uniq -d)
|
||||||
|
|
||||||
# Display results
|
# Display results
|
||||||
if [ -z "$DUPLICATE_REPLACES" ]; then
|
if [ -z "$DUPLICATE_REPLACES" ]; then
|
||||||
echo "Success: All replace values are unique!"
|
echo -e "${GREEN}${BOLD}✓ Success:${RESET} ${GREEN}All replace values are unique!${RESET}"
|
||||||
TOTAL_REPLACES=$(wc -l < "$ALL_REPLACES")
|
TOTAL_REPLACES=$(wc -l < "$ALL_REPLACES")
|
||||||
echo "Total number of replace values found: $TOTAL_REPLACES"
|
echo -e "${CYAN}Total number of replace values found:${RESET} ${BOLD}$TOTAL_REPLACES${RESET}"
|
||||||
else
|
else
|
||||||
echo "Error: Duplicate replace values found:"
|
echo -e "${RED}${BOLD}✗ Error:${RESET} ${RED}Duplicate replace values found:${RESET}"
|
||||||
echo "$DUPLICATE_REPLACES"
|
echo -e "${YELLOW}$DUPLICATE_REPLACES${RESET}"
|
||||||
|
|
||||||
# Optional: Show which files contain each duplicate replace value
|
# Show detailed information for each duplicate
|
||||||
echo -e "\nDuplicates found in these files:"
|
echo -e "\n${CYAN}${BOLD}Detailed information for duplicates:${RESET}"
|
||||||
for dupe in $DUPLICATE_REPLACES; do
|
for dupe in $DUPLICATE_REPLACES; do
|
||||||
echo "Replace value \"$dupe\" found in:"
|
echo -e "\n${MAGENTA}${BOLD}Replace value${RESET} ${BOLD}\"$dupe\"${RESET} ${MAGENTA}found:${RESET}"
|
||||||
grep -l "replace: \"$dupe\"" "$MATCH_DIR"/*.y*ml
|
grep "^$dupe|" "$ALL_REPLACES_DATA" | while IFS='|' read -r replace trigger file trigger_line replace_line; do
|
||||||
|
echo -e " ${YELLOW}→${RESET} Line ${MAGENTA}${BOLD}$replace_line${RESET} in ${BLUE}$file${RESET}: ${CYAN}trigger=${RESET}\"${GREEN}$trigger${RESET}\""
|
||||||
|
done
|
||||||
done
|
done
|
||||||
|
rm "$ALL_TRIGGERS" "$ALL_REPLACES" "$ALL_TRIGGERS_DATA" "$ALL_REPLACES_DATA"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
rm "$ALL_TRIGGERS"
|
rm "$ALL_TRIGGERS" "$ALL_REPLACES" "$ALL_TRIGGERS_DATA" "$ALL_REPLACES_DATA"
|
||||||
rm "$ALL_REPLACES"
|
|
||||||
|
|
||||||
### Now we test that all gifs.yml replace values match "c.tenor.com".
|
### Now we test that all gifs.yml replace values match "c.tenor.com".
|
||||||
|
|
||||||
@@ -90,31 +138,31 @@ rm "$ALL_REPLACES"
|
|||||||
REPLACE_VALUES=$(mktemp)
|
REPLACE_VALUES=$(mktemp)
|
||||||
|
|
||||||
# Read gifs.yml file and extract replace values
|
# Read gifs.yml file and extract replace values
|
||||||
echo "Scanning gifs.yml for replace values..."
|
echo -e "${CYAN}${BOLD}Scanning gifs.yml for replace values...${RESET}"
|
||||||
if [ -f "$MATCH_DIR/gifs.yml" ]; then
|
if [ -f "$MATCH_DIR/gifs.yml" ]; then
|
||||||
# We match lines like: ` replace: "https://c.tenor.com/some-value/tenor.gif"`
|
# We match lines like: ` replace: "https://c.tenor.com/some-value/tenor.gif"`
|
||||||
grep -E '^\s*replace:' "$MATCH_DIR/gifs.yml" | sed 's/.*replace:\s*"\([^"]*\)".*/\1/' >> "$REPLACE_VALUES"
|
grep -E '^\s*replace:' "$MATCH_DIR/gifs.yml" | sed 's/.*replace:\s*"\([^"]*\)".*/\1/' >> "$REPLACE_VALUES"
|
||||||
else
|
else
|
||||||
echo "Error: gifs.yml file not found in $MATCH_DIR directory!"
|
echo -e "${RED}${BOLD}Error:${RESET} ${RED}gifs.yml file not found in $MATCH_DIR directory!${RESET}"
|
||||||
rm "$REPLACE_VALUES"
|
rm "$REPLACE_VALUES"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if we found any replace values
|
# Check if we found any replace values
|
||||||
if [ ! -s "$REPLACE_VALUES" ]; then
|
if [ ! -s "$REPLACE_VALUES" ]; then
|
||||||
echo "No replace values found in gifs.yml. Check file format."
|
echo -e "${RED}${BOLD}Error:${RESET} ${RED}No replace values found in gifs.yml. Check file format.${RESET}"
|
||||||
rm "$REPLACE_VALUES"
|
rm "$REPLACE_VALUES"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if all replace values start with "https://c.tenor.com/"
|
# Check if all replace values start with "https://c.tenor.com/"
|
||||||
echo -e "\nChecking replace values in gifs.yml..."
|
echo -e "\n${CYAN}${BOLD}Checking replace values in gifs.yml...${RESET}"
|
||||||
INVALID_REPLACE=$(grep -v '^https://c\.tenor\.com/' "$REPLACE_VALUES")
|
INVALID_REPLACE=$(grep -v '^https://c\.tenor\.com/' "$REPLACE_VALUES")
|
||||||
if [ -z "$INVALID_REPLACE" ]; then
|
if [ -z "$INVALID_REPLACE" ]; then
|
||||||
echo "Success: All replace values in gifs.yml are valid!"
|
echo -e "${GREEN}${BOLD}✓ Success:${RESET} ${GREEN}All replace values in gifs.yml are valid!${RESET}"
|
||||||
else
|
else
|
||||||
echo "Error: Invalid replace values found in gifs.yml:"
|
echo -e "${RED}${BOLD}✗ Error:${RESET} ${RED}Invalid replace values found in gifs.yml:${RESET}"
|
||||||
echo "$INVALID_REPLACE"
|
echo -e "${YELLOW}$INVALID_REPLACE${RESET}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user