From dc50b4bcd0fb24cd7a543fdcf9b666721961558a Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Thu, 31 Oct 2024 19:03:59 +0100 Subject: [PATCH] fix: improve bashrc sourcing and zoxide initialization; add home-manager installation check --- .bashrc | 18 ++++++++++++++---- bin/actions/update.sh | 13 +++++++++++++ setup.sh | 4 ++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.bashrc b/.bashrc index 9497adb..baca387 100644 --- a/.bashrc +++ b/.bashrc @@ -89,18 +89,28 @@ fi eval "$(starship init bash)" # Source nix home-manager -. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" +if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then + . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" +fi # Source agent-bridge script for 1password source $HOME/dotfiles/bin/1password-agent-bridge.sh -# zoxide -eval "$(zoxide init bash)" +# zoxide if available +if command -v zoxide &> /dev/null; then + eval "$(zoxide init bash)" +fi # Check if we are running from zellij, if not then launch it if [ -z "$ZELLIJ" ]; then zellij - exit $? + + # Exit if zellij exits properly with a zero exit code + if [ $? -eq 0 ]; then + exit $? + fi + + echo "Zellij exited with a non-zero exit code, continuing..." return fi diff --git a/bin/actions/update.sh b/bin/actions/update.sh index d04c8ac..404bdc6 100755 --- a/bin/actions/update.sh +++ b/bin/actions/update.sh @@ -209,6 +209,18 @@ homemanager() { cd $HOME/dotfiles/config/home-manager && home-manager switch } +ensure_homemanager_installed() { + if [ ! -x "$(command -v home-manager)" ]; then + printfe "%s\n" "yellow" "Home Manager is not installed, installing it..." + nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager + nix-channel --update + nix-shell '' -A install + + printfe "%s\n" "yellow" "Home Manager installed, please run the script again." + exit 1 + fi +} + #################################################################################################### # Parse arguments #################################################################################################### @@ -223,6 +235,7 @@ shift if [ "$#" -eq 0 ]; then printfe "%s\n" "yellow" "No options passed, running full update..." + ensure_homemanager_installed symlinks sys_packages homemanager diff --git a/setup.sh b/setup.sh index 3956a46..6fe8e47 100755 --- a/setup.sh +++ b/setup.sh @@ -17,6 +17,10 @@ if [ ! -x "$(command -v sed)" ]; then return fi +if [ ! -f ~/.bashrc ]; then + touch ~/.bashrc +fi + sed -i -e '$a\'$'\n''export PATH=$PATH:$HOME/.local/bin' ~/.bashrc sed -i -e '$a\'$'\n''export PATH=$PATH:~/dotfiles/bin' ~/.bashrc