diff --git a/setup_env.sh b/setup_env.sh index d6570bf..4e70fbe 100755 --- a/setup_env.sh +++ b/setup_env.sh @@ -2,10 +2,18 @@ # Function to install packages install_packages() { - echo "Updating package list..." + local packages=(tmux vim git pspg bat fzf ripgrep) + local missing=() + for pkg in "${packages[@]}"; do + command -v "$pkg" &>/dev/null || missing+=("$pkg") + done + if [[ ${#missing[@]} -eq 0 ]]; then + echo "All packages already installed, skipping." + return + fi + echo "Installing missing packages: ${missing[*]}" sudo apt update - echo "Installing basic packages..." - sudo apt install -y tmux vim git pspg bat fzf ripgrep + sudo apt install -y "${missing[@]}" } # Install Tmux Plugin Manager (TPM) if not already installed @@ -38,11 +46,15 @@ install_git_bash_prompt() { fi } -# Back up and create symlink +# Back up and create symlink — skips if already pointing at the right target create_symlink() { local target=$1 local link_name=$2 + if [[ -L $link_name && "$(readlink "$link_name")" == "$target" ]]; then + return + fi + if [[ -L $link_name || -f $link_name ]]; then echo "Backing up existing $link_name to ${link_name}.backup" mv "$link_name" "${link_name}.backup"