-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·55 lines (46 loc) · 1.65 KB
/
install.sh
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
#!/bin/sh
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if sgpt is installed
if ! command_exists sgpt; then
echo "Error: sgpt is not installed. Please install shell_gpt first."
echo "Visit https://github.com/TheR1D/shell_gpt for installation instructions."
exit 1
fi
# Determine the user's login shell
USER_SHELL=$(basename "$SHELL")
case "$USER_SHELL" in
zsh)
RCFILE="$HOME/.zshrc"
;;
bash)
RCFILE="$HOME/.bashrc"
;;
*)
echo "Unsupported shell ($USER_SHELL). Please add the following lines manually to your shell's rc file:"
echo "### BEGIN .unicornsh"
echo "source ~/.unicornsh/unicornsh.source"
echo "### END .unicornsh"
exit 1
;;
esac
# Check if .unicornsh is already installed
if grep -q "### BEGIN .unicornsh" "$RCFILE"; then
echo ".unicornsh is already installed. Skipping rc file modification."
else
# Add guarded source line and PATH update to the appropriate rc file
echo "### BEGIN .unicornsh" >> "$RCFILE"
echo "source ~/.unicornsh/unicornsh.source" >> "$RCFILE"
echo 'export PATH="$PATH:$HOME/.unicornsh/scripts"' >> "$RCFILE"
echo "### END .unicornsh" >> "$RCFILE"
echo "Added .unicornsh configuration to $RCFILE"
# Add symlink
ln -s ~/.unicornsh ~/.🦄sh
fi
# Install sgpt functions
sgpt --install-functions
# Remove existing functions directory and create symlink
rm -rf ~/.config/shell_gpt/functions && ln -s ~/.unicornsh/functions ~/.config/shell_gpt/functions
echo "Installation complete! Please restart your shell or run 'source $RCFILE' to apply changes."