-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·220 lines (191 loc) · 6.71 KB
/
install.sh
File metadata and controls
executable file
·220 lines (191 loc) · 6.71 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/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
# --- Installation configuration ---
INSTALL_DIR="$HOME/.config/ff"
REPO_BASE_URL="https://raw.githubusercontent.com/the0807/ff/main"
echo -e "${BLUE}╔════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}║ 🔍 ff - Flexible File Finder Installer ║${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════╝${NC}"
echo ""
# --- 1. Check for fzf (Required) ---
echo -e "${BLUE}[1/4]${NC} Checking dependencies..."
if ! command -v fzf >/dev/null 2>&1; then
echo -e "${RED}✗${NC} fzf is not installed!"
echo ""
echo "fzf is required for ff to work."
exit 1
fi
echo -e "${GREEN}✓${NC} fzf found"
# --- Check optional dependencies ---
OPTIONAL_TOOLS=("rg" "eza" "tree")
FOUND_TOOLS=()
MISSING_TOOLS=()
# Check bat/batcat separately (either one is fine)
if command -v batcat >/dev/null 2>&1; then
FOUND_TOOLS+=("batcat")
elif command -v bat >/dev/null 2>&1; then
FOUND_TOOLS+=("bat")
else
MISSING_TOOLS+=("bat(batcat)")
fi
# Check fd/fdfind separately (either one is fine)
if command -v fd >/dev/null 2>&1; then
FOUND_TOOLS+=("fd")
elif command -v fdfind >/dev/null 2>&1; then
FOUND_TOOLS+=("fdfind")
else
MISSING_TOOLS+=("fd(fdfind)")
fi
# Check other optional tools
for tool in "${OPTIONAL_TOOLS[@]}"; do
if command -v "$tool" >/dev/null 2>&1; then
FOUND_TOOLS+=("$tool")
else
MISSING_TOOLS+=("$tool")
fi
done
if [ ${#FOUND_TOOLS[@]} -gt 0 ]; then
echo -e "${GREEN}✓${NC} Optional tools found: ${FOUND_TOOLS[*]}"
fi
if [ ${#MISSING_TOOLS[@]} -gt 0 ]; then
echo -e "${YELLOW}i${NC} Optional tools missing: ${MISSING_TOOLS[*]}"
echo -e " ${YELLOW}(Install these for better experience)${NC}"
fi
# --- 2. Detect Shell & Config File (Robust) ---
echo ""
echo -e "${BLUE}[2/5]${NC} Detecting shell..."
USER_SHELL=$(basename "$SHELL")
SHELL_CONFIG=""
INSTALL_FILE=""
REPO_URL=""
case "$USER_SHELL" in
zsh)
SHELL_NAME="zsh"
SHELL_CONFIG="$HOME/.zshrc"
INSTALL_FILE="$INSTALL_DIR/ff.sh"
REPO_URL="$REPO_BASE_URL/ff.sh"
;;
bash)
SHELL_NAME="bash"
INSTALL_FILE="$INSTALL_DIR/ff.sh"
REPO_URL="$REPO_BASE_URL/ff.sh"
if [[ "$OSTYPE" == "darwin"* && -f "$HOME/.bash_profile" ]]; then
SHELL_CONFIG="$HOME/.bash_profile"
else
SHELL_CONFIG="$HOME/.bashrc"
fi
;;
fish)
SHELL_NAME="fish"
SHELL_CONFIG="$HOME/.config/fish/config.fish"
INSTALL_FILE="$INSTALL_DIR/ff.fish"
REPO_URL="$REPO_BASE_URL/ff.fish"
# Ensure fish config directory exists
mkdir -p "$HOME/.config/fish"
;;
*)
echo -e "${YELLOW}⚠${NC} Could not auto-detect shell type (Current: $USER_SHELL)."
echo "Supported shells: bash, zsh, fish"
echo ""
echo "For bash/zsh, manually add this line to your config file:"
echo " source $INSTALL_DIR/ff.sh"
echo ""
echo "For fish, manually add this line to ~/.config/fish/config.fish:"
echo " source $INSTALL_DIR/ff.fish"
exit 0
;;
esac
echo -e "${GREEN}✓${NC} Detected shell: $SHELL_NAME"
echo -e "${GREEN}✓${NC} Target config: $SHELL_CONFIG"
echo -e "${GREEN}✓${NC} Install file: $INSTALL_FILE"
# --- 3. Create installation directory ---
echo ""
echo -e "${BLUE}[3/5]${NC} Creating installation directory..."
mkdir -p "$INSTALL_DIR"
echo -e "${GREEN}✓${NC} Directory created: $INSTALL_DIR"
# --- 4. Download scripts (curl/wget fallback) ---
echo ""
echo -e "${BLUE}[4/5]${NC} Downloading scripts..."
# Download main script
if command -v curl >/dev/null 2>&1; then
if curl -fsSL "$REPO_URL" -o "$INSTALL_FILE"; then
echo -e "${GREEN}✓${NC} Downloaded (via curl): $(basename $INSTALL_FILE)"
else
echo -e "${RED}✗${NC} Download failed using curl"
exit 1
fi
elif command -v wget >/dev/null 2>&1; then
if wget -qO "$INSTALL_FILE" "$REPO_URL"; then
echo -e "${GREEN}✓${NC} Downloaded (via wget): $(basename $INSTALL_FILE)"
else
echo -e "${RED}✗${NC} Download failed using wget"
exit 1
fi
else
echo -e "${RED}✗${NC} Neither curl nor wget found."
exit 1
fi
chmod +x "$INSTALL_FILE"
# Download uninstall script
UNINSTALL_FILE="$INSTALL_DIR/uninstall.sh"
UNINSTALL_URL="$REPO_BASE_URL/uninstall.sh"
if command -v curl >/dev/null 2>&1; then
if curl -fsSL "$UNINSTALL_URL" -o "$UNINSTALL_FILE"; then
echo -e "${GREEN}✓${NC} Downloaded (via curl): uninstall.sh"
else
echo -e "${YELLOW}⚠${NC} Failed to download uninstall.sh (non-critical)"
fi
elif command -v wget >/dev/null 2>&1; then
if wget -qO "$UNINSTALL_FILE" "$UNINSTALL_URL"; then
echo -e "${GREEN}✓${NC} Downloaded (via wget): uninstall.sh"
else
echo -e "${YELLOW}⚠${NC} Failed to download uninstall.sh (non-critical)"
fi
fi
if [ -f "$UNINSTALL_FILE" ]; then
chmod +x "$UNINSTALL_FILE"
fi
# --- 5. Add to shell config (with Backup) ---
echo ""
echo -e "${BLUE}[5/5]${NC} Updating configuration..."
SOURCE_LINE="source $INSTALL_FILE"
if grep -Fq "$SOURCE_LINE" "$SHELL_CONFIG" 2>/dev/null; then
echo -e "${YELLOW}i${NC} Already configured in $SHELL_CONFIG"
else
# Create backup
if [ -f "$SHELL_CONFIG" ]; then
cp "$SHELL_CONFIG" "${SHELL_CONFIG}.bak"
echo -e "${GREEN}✓${NC} Created backup at ${SHELL_CONFIG}.bak"
fi
# Add to config file
echo "" >> "$SHELL_CONFIG"
echo "# ff - Flexible File Finder" >> "$SHELL_CONFIG"
if [ "$SHELL_NAME" = "fish" ]; then
# Fish uses 'source' command
echo "source $INSTALL_FILE" >> "$SHELL_CONFIG"
else
# Bash/Zsh use 'source' command
echo "source $INSTALL_FILE" >> "$SHELL_CONFIG"
fi
echo -e "${GREEN}✓${NC} Added to $SHELL_CONFIG"
fi
# --- Success Message ---
echo ""
echo -e "${GREEN}╔════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ✓ Installation completed! 🎉 ║${NC}"
echo -e "${GREEN}╚════════════════════════════════════════╝${NC}"
echo ""
echo "To start using ff, run:"
echo -e " ${BLUE}source $SHELL_CONFIG${NC}"
echo ""
if [ -f "$INSTALL_DIR/uninstall.sh" ]; then
echo "To uninstall ff later, run:"
echo -e " ${BLUE}bash $INSTALL_DIR/uninstall.sh${NC}"
echo ""
fi