Skip to content

Commit 70cd954

Browse files
committed
bug(uninstall.sh): Fixed timestamp reliance in backup.
1 parent 3ac8153 commit 70cd954

File tree

2 files changed

+52
-21
lines changed

2 files changed

+52
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The installer adds an `include` directive to your `~/.XCompose`, preserving any
103103
Clone like previous step. Add this line to your `~/.XCompose`:
104104

105105
```bash
106-
include "$HOME/.xcompose-stem/XCompose"
106+
include "%H/.xcompose-stem/XCompose"
107107
```
108108

109109
If `~/.XCompose` doesn't exist, create it:
@@ -113,7 +113,7 @@ If `~/.XCompose` doesn't exist, create it:
113113
include "%L"
114114

115115
# Include xcompose-stem
116-
include "$HOME/.xcompose-stem/XCompose"
116+
include "%H/.xcompose-stem/XCompose"
117117
```
118118

119119
### Activation

uninstall.sh

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ set -e
1414
# original configuration.
1515

1616
XCOMPOSE_FILE="$HOME/.XCompose"
17-
BACKUP_FILE="$HOME/.XCompose.backup.$(date +%Y%m%d_%H%M%S)"
1817

1918
# Colors for output
2019
RED='\033[0;31m'
@@ -39,26 +38,56 @@ if ! grep -q "include.*xcompose-stem.*XCompose" "$XCOMPOSE_FILE" 2>/dev/null; th
3938
exit 0
4039
fi
4140

42-
# Backup existing file
43-
echo -e "Creating backup: ${BACKUP_FILE}"
44-
cp "$XCOMPOSE_FILE" "$BACKUP_FILE"
41+
# Find the most recent pre-installation backup
42+
INSTALL_BACKUP=$(ls -t "$HOME"/.XCompose.backup.* 2>/dev/null | head -1)
4543

46-
# Remove xcompose-stem lines (only the include and related comments)
47-
echo "Removing xcompose-stem from ~/.XCompose..."
48-
# Remove the comment line above the include
49-
sed -i '/^# xcompose-stem - STEM symbols for technical writing$/d' "$XCOMPOSE_FILE"
50-
# Remove the GitHub URL comment
51-
sed -i '\|^# https://github.com/phil-bowens/xcompose-stem$|d' "$XCOMPOSE_FILE"
52-
# Remove the actual include line
53-
sed -i '\|^include.*xcompose-stem.*XCompose"$|d' "$XCOMPOSE_FILE"
44+
if [ -n "$INSTALL_BACKUP" ]; then
45+
echo -e "${YELLOW}Found backup from installation:${NC} $(basename "$INSTALL_BACKUP")"
46+
echo ""
47+
read -p "Restore from this backup? (Y/n): " -n 1 -r
48+
echo ""
5449

55-
# Remove excess empty lines that might have been left behind
56-
sed -i '/^$/N;/^\n$/D' "$XCOMPOSE_FILE"
50+
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
51+
# Restore from backup
52+
cp "$INSTALL_BACKUP" "$XCOMPOSE_FILE"
53+
echo -e "${GREEN}✓ Restored from backup!${NC}"
54+
echo "Your original ~/.XCompose has been restored."
55+
else
56+
# Manual removal
57+
UNINSTALL_BACKUP="$HOME/.XCompose.backup.uninstall.$(date +%Y%m%d_%H%M%S)"
58+
echo -e "Creating backup: ${UNINSTALL_BACKUP}"
59+
cp "$XCOMPOSE_FILE" "$UNINSTALL_BACKUP"
60+
61+
# Remove xcompose-stem lines
62+
echo "Removing xcompose-stem from ~/.XCompose..."
63+
sed -i '/^# xcompose-stem - STEM symbols for technical writing$/d' "$XCOMPOSE_FILE"
64+
sed -i '\|^# https://github.com/phil-bowens/xcompose-stem$|d' "$XCOMPOSE_FILE"
65+
sed -i '\|^include.*xcompose-stem.*XCompose"$|d' "$XCOMPOSE_FILE"
66+
sed -i '/^$/N;/^\n$/D' "$XCOMPOSE_FILE"
67+
68+
echo -e "${GREEN}✓ Removed xcompose-stem lines${NC}"
69+
echo -e "Backup saved: ${UNINSTALL_BACKUP}"
70+
fi
71+
else
72+
# No backup found - do manual removal
73+
echo -e "${YELLOW}No installation backup found.${NC}"
74+
UNINSTALL_BACKUP="$HOME/.XCompose.backup.uninstall.$(date +%Y%m%d_%H%M%S)"
75+
echo -e "Creating backup: ${UNINSTALL_BACKUP}"
76+
cp "$XCOMPOSE_FILE" "$UNINSTALL_BACKUP"
77+
78+
# Remove xcompose-stem lines
79+
echo "Removing xcompose-stem from ~/.XCompose..."
80+
sed -i '/^# xcompose-stem - STEM symbols for technical writing$/d' "$XCOMPOSE_FILE"
81+
sed -i '\|^# https://github.com/phil-bowens/xcompose-stem$|d' "$XCOMPOSE_FILE"
82+
sed -i '\|^include.*xcompose-stem.*XCompose"$|d' "$XCOMPOSE_FILE"
83+
sed -i '/^$/N;/^\n$/D' "$XCOMPOSE_FILE"
84+
85+
echo -e "${GREEN}✓ Removed xcompose-stem lines${NC}"
86+
echo -e "Backup saved: ${UNINSTALL_BACKUP}"
87+
fi
5788

58-
echo -e "${GREEN}✓ Uninstallation complete!${NC}"
5989
echo ""
60-
echo "xcompose-stem has been removed from ~/.XCompose"
61-
echo -e "Backup saved: ${BACKUP_FILE}"
90+
echo -e "${GREEN}✓ Uninstallation complete!${NC}"
6291
echo ""
6392

6493
echo -e "${BLUE}Reloading XCompose...${NC}"
@@ -77,6 +106,8 @@ fi
77106
echo ""
78107
echo "Your previous Compose sequences should still work."
79108
echo ""
80-
echo -e "${YELLOW}Note:${NC} You can restore your previous config with:"
81-
echo " cp $BACKUP_FILE ~/.XCompose"
109+
if [ -n "$INSTALL_BACKUP" ]; then
110+
echo -e "${YELLOW}Note:${NC} If needed, you can find backups in your home directory:"
111+
echo " ls -lt ~/.XCompose.backup.*"
112+
fi
82113
echo ""

0 commit comments

Comments
 (0)