Files
espanso/push.sh
T

97 lines
3.4 KiB
Bash
Executable File

#! /usr/bin/bash
# Color definitions
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}"