Skip to content

Commit db32905

Browse files
Merge pull request #1 from pico190/patch-1
Add support for fish shell
2 parents 2dc52bb + c2d5089 commit db32905

File tree

1 file changed

+70
-25
lines changed

1 file changed

+70
-25
lines changed

docs/install.sh

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,41 +139,86 @@ add_app_to_path() {
139139
exit 1
140140
fi
141141

142-
# check if it's already in PATH
143-
if [[ ":$PATH:" == *":$INSTALL_DIR:"* ]]; then
144-
echo "$INSTALL_DIR is already in PATH."
145-
return
146-
fi
142+
# detect current shell name (bash, zsh, fish, etc.)
143+
local shell_name
144+
shell_name="$(basename "${SHELL:-}")"
145+
146+
echo "Detected shell: ${shell_name:-unknown}"
147147

148-
# define target files
149-
FILES=("$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.profile")
148+
# default bash-like files
149+
local FILES_BASH=("$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.profile")
150+
# zsh config
151+
local FILES_ZSH=("$HOME/.zshrc")
152+
# fish config
153+
local FISH_CONFIG="$HOME/.config/fish/config.fish"
150154

151155
local modified=0
152156

153-
modified=0
157+
case "$shell_name" in
158+
bash|"")
159+
echo "Configuring PATH for Bash-compatible shells..."
160+
for file in "${FILES_BASH[@]}"; do
161+
if [ -f "$file" ]; then
162+
if ! grep -q "$INSTALL_DIR" "$file"; then
163+
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >>"$file"
164+
echo "Added $INSTALL_DIR to PATH in $file"
165+
modified=1
166+
else
167+
echo "$INSTALL_DIR is already in $file."
168+
fi
169+
fi
170+
done
171+
;;
172+
173+
zsh)
174+
echo "Configuring PATH for zsh..."
175+
for file in "${FILES_ZSH[@]}"; do
176+
# create file if it doesn't exist
177+
if [ ! -f "$file" ]; then
178+
touch "$file"
179+
fi
180+
if ! grep -q "$INSTALL_DIR" "$file"; then
181+
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >>"$file"
182+
echo "Added $INSTALL_DIR to PATH in $file"
183+
modified=1
184+
else
185+
echo "$INSTALL_DIR is already in $file."
186+
fi
187+
done
188+
;;
154189

155-
# append to each file if it exists and doesn't already contain the entry
156-
for file in "${FILES[@]}"; do
157-
if [ -f "$file" ]; then
158-
if ! grep -q "$INSTALL_DIR" "$file"; then
159-
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >>"$file"
160-
echo "Added $INSTALL_DIR to PATH in $file"
190+
fish)
191+
echo "Configuring PATH for fish..."
192+
mkdir -p "$(dirname "$FISH_CONFIG")"
193+
if [ ! -f "$FISH_CONFIG" ]; then
194+
touch "$FISH_CONFIG"
195+
fi
196+
if ! grep -q "$INSTALL_DIR" "$FISH_CONFIG" 2>/dev/null; then
197+
# fish uses fish_add_path to manage PATH cleanly
198+
echo "fish_add_path \"$INSTALL_DIR\" 2>/dev/null; or set -gx PATH \"$INSTALL_DIR\" \$PATH" >>"$FISH_CONFIG"
199+
echo "Added $INSTALL_DIR to PATH in $FISH_CONFIG"
161200
modified=1
162201
else
163-
echo "$INSTALL_DIR is already in $file."
202+
echo "$INSTALL_DIR is already in $FISH_CONFIG."
164203
fi
165-
else
166-
echo "File $file not found."
167-
fi
168-
done
204+
;;
205+
206+
*)
207+
echo "Unknown shell '$shell_name'. Falling back to Bash-style config files."
208+
for file in "${FILES_BASH[@]}"; do
209+
if [ -f "$file" ]; then
210+
if ! grep -q "$INSTALL_DIR" "$file"; then
211+
echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >>"$file"
212+
echo "Added $INSTALL_DIR to PATH in $file"
213+
modified=1
214+
fi
215+
fi
216+
done
217+
;;
218+
esac
169219

170-
# apply changes if any file was modified
171220
if (( modified == 1 )); then
172-
echo "Reloading shell config files..."
173-
source "$HOME/.profile" 2>/dev/null || true
174-
source "$HOME/.bashrc" 2>/dev/null || true
175-
source "$HOME/.bash_profile" 2>/dev/null || true
176-
echo "Successfully added $INSTALL_DIR to PATH."
221+
echo "PATH config updated. Please restart your terminal or re-source your shell config (e.g., 'source ~/.bashrc', 'source ~/.zshrc', or 'exec fish')."
177222
else
178223
echo "No PATH was modified."
179224
fi

0 commit comments

Comments
 (0)