-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·132 lines (107 loc) · 3.87 KB
/
uninstall.sh
File metadata and controls
executable file
·132 lines (107 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env bash
set -e
# --- Colors for output ---
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# --- Uninstallation configuration ---
INSTALL_DIR="$HOME/.config/ff"
BACKUP_SUFFIX=".ff_backup_$(date +%Y%m%d_%H%M%S)"
echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ 🗑️ ff - Flexible File Finder Uninstaller ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
echo ""
# --- 1. Confirmation prompt ---
echo -e "${YELLOW}⚠️ This will remove ff from your system.${NC}"
echo ""
echo "The following will be removed:"
echo " - Installation directory: $INSTALL_DIR"
echo " - Source lines from shell configuration files"
echo ""
read -p "Do you want to continue? [y/N] " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${BLUE}Uninstallation cancelled.${NC}"
exit 0
fi
echo ""
# --- 2. Remove installation directory ---
echo -e "${BLUE}[1/3]${NC} Removing installation directory..."
if [ -d "$INSTALL_DIR" ]; then
rm -rf "$INSTALL_DIR"
echo -e "${GREEN}✓${NC} Removed: $INSTALL_DIR"
else
echo -e "${YELLOW}i${NC} Directory not found: $INSTALL_DIR"
fi
# --- 3. Detect and clean shell configurations ---
echo ""
echo -e "${BLUE}[2/3]${NC} Cleaning shell configuration files..."
USER_SHELL=$(basename "$SHELL")
CLEANED_FILES=0
# Function to remove ff lines from a config file
remove_ff_lines() {
local config_file="$1"
local source_pattern="$2"
if [ ! -f "$config_file" ]; then
return
fi
# Check if ff is configured
if ! grep -q "$source_pattern" "$config_file" 2>/dev/null; then
return
fi
# Create backup
cp "$config_file" "${config_file}${BACKUP_SUFFIX}"
echo -e "${GREEN}✓${NC} Created backup: ${config_file}${BACKUP_SUFFIX}"
# Remove ff-related lines (comment line + source line)
sed -i.tmp '/# ff - Flexible File Finder/d; \|'"$source_pattern"'|d' "$config_file"
rm -f "${config_file}.tmp"
echo -e "${GREEN}✓${NC} Cleaned: $config_file"
CLEANED_FILES=$((CLEANED_FILES + 1))
}
# Clean Bash configuration
if [ -f "$HOME/.bashrc" ]; then
remove_ff_lines "$HOME/.bashrc" "source.*/.config/ff/ff.sh"
fi
if [ -f "$HOME/.bash_profile" ]; then
remove_ff_lines "$HOME/.bash_profile" "source.*/.config/ff/ff.sh"
fi
# Clean Zsh configuration
if [ -f "$HOME/.zshrc" ]; then
remove_ff_lines "$HOME/.zshrc" "source.*/.config/ff/ff.sh"
fi
# Clean Fish configuration
if [ -f "$HOME/.config/fish/config.fish" ]; then
remove_ff_lines "$HOME/.config/fish/config.fish" "source.*/.config/ff/ff.fish"
fi
if [ $CLEANED_FILES -eq 0 ]; then
echo -e "${YELLOW}i${NC} No ff configuration found in shell config files"
fi
# --- 4. Final message ---
echo ""
echo -e "${BLUE}[3/3]${NC} Cleanup complete!"
echo ""
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ✓ Uninstallation completed! 🎉 ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════╝${NC}"
echo ""
if [ $CLEANED_FILES -gt 0 ]; then
echo "Backup files created with suffix: ${BACKUP_SUFFIX}"
echo ""
echo "To complete the removal, restart your shell or run:"
case "$USER_SHELL" in
zsh)
echo -e " ${BLUE}source ~/.zshrc${NC}"
;;
bash)
echo -e " ${BLUE}source ~/.bashrc${NC}"
;;
fish)
echo -e " ${BLUE}source ~/.config/fish/config.fish${NC}"
;;
esac
echo ""
fi
echo "Thank you for using ff! 👋"
echo ""