Update fastfetch-setup.sh - improved logic

This commit is contained in:
mateuszkozako 2025-01-20 11:09:39 +01:00 committed by GitHub
parent 032e26b566
commit 9cb5d3a7c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,20 +6,20 @@ installFastfetch() {
if ! command_exists fastfetch; then
printf "%b\n" "${YELLOW}Installing Fastfetch...${RC}"
case "$PACKAGER" in
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm fastfetch
;;
apt-get|nala)
curl -sSLo /tmp/fastfetch.deb https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-amd64.deb
"$ESCALATION_TOOL" "$PACKAGER" install -y /tmp/fastfetch.deb
rm /tmp/fastfetch.deb
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add fastfetch
;;
*)
"$ESCALATION_TOOL" "$PACKAGER" install -y fastfetch
;;
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm fastfetch
;;
apt-get | nala)
curl -sSLo /tmp/fastfetch.deb https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-amd64.deb
"$ESCALATION_TOOL" "$PACKAGER" install -y /tmp/fastfetch.deb
rm /tmp/fastfetch.deb
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add fastfetch
;;
*)
"$ESCALATION_TOOL" "$PACKAGER" install -y fastfetch
;;
esac
else
printf "%b\n" "${GREEN}Fastfetch is already installed.${RC}"
@ -37,50 +37,50 @@ setupFastfetchConfig() {
setupFastfetchShell() {
printf "%b\n" "${YELLOW}Configuring shell integration...${RC}"
# Get current shell and RC file path
current_shell=$(basename "$SHELL")
rc_file=""
case "$current_shell" in
"bash")
rc_file="$HOME/.bashrc"
;;
"zsh")
rc_file="$HOME/.zshrc"
;;
*)
printf "%b\n" "${RED}Unsupported shell: $current_shell${RC}"
return 1
;;
"bash")
rc_file="$HOME/.bashrc"
;;
"zsh")
rc_file="$HOME/.zshrc"
;;
*)
printf "%b\n" "${RED}You sre using shell other than zsh and bash, your shell is: $current_shell${RC}, therefore you have to manually update your rc file."
other_shell=True
;;
esac
# Check if RC file exists
if [ ! -f "$rc_file" ]; then
printf "%b\n" "${RED}Shell config file not found: $rc_file${RC}"
return 1
fi
# Check if fastfetch is already in RC file
if grep -q "fastfetch" "$rc_file"; then
printf "%b\n" "${YELLOW}Fastfetch is already configured in $rc_file${RC}"
return 0
fi
# Ask for confirmation
printf "%b" "${GREEN}Would you like to add fastfetch to $rc_file? [y/N] ${RC}"
read -r response
if [ "$response" = "y" ] || [ "$response" = "Y" ]; then
printf "\n# Run fastfetch on terminal start\nfastfetch\n" >> "$rc_file"
printf "%b\n" "${GREEN}Added fastfetch to $rc_file${RC}"
if [ ! -f "$rc_file" ] || [ "$other_shell" != "True" ]; then
printf "%b\n" "${RED}Shell config file $rc_file${RC} not found"
else
printf "%b\n" "${YELLOW}Skipped adding fastfetch to shell config${RC}"
# Check if fastfetch is already in RC file
if grep -q "fastfetch" "$rc_file"; then
printf "%b\n" "${YELLOW}Fastfetch is already configured in $rc_file${RC}"
return 0
else
# Ask for confirmation
printf "%b" "${GREEN}Would you like to add fastfetch to $rc_file? [y/N] ${RC}"
read -r response
if [ "$response" = "y" ] || [ "$response" = "Y" ]; then
printf "\n# Run fastfetch on terminal start\nfastfetch\n" >>"$rc_file"
printf "%b\n" "${GREEN}Added fastfetch to $rc_file${RC}"
else
printf "%b\n" "${YELLOW}Skipped adding fastfetch to shell config${RC}"
fi
fi
fi
}
checkEnv
checkEscalationTool
installFastfetch
setupFastfetchConfig
setupFastfetchShell
setupFastfetchShell