summaryrefslogtreecommitdiff
path: root/fedora/.config/bash/packages.bash
blob: 27d396ea640dd49e6e8c2da7fff30e47ac5e27cd (plain)
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
#!/bin/bash

# --- Packages (bash version) ---
declare -A packages=(
  # [zoxide]="--cmd cd --hook prompt"
)

eval_packages() {
  local package output
  for package in "${!packages[@]}"; do
    if command -v "$package" >/dev/null 2>&1; then
      # split args by space into array (preserve empty => zero args)
      local -a args=()
      if [[ -n "${packages[$package]}" ]]; then
        # Use builtin read to split on spaces (simple split)
        IFS=' ' read -r -a args <<<"${packages[$package]}"
      fi

      # Prefer initializing for bash (change to "zsh" if you really want zsh-init)
      if ((${#args[@]})); then
        output="$("$package" init bash "${args[@]}" 2>/dev/null)"
      else
        output="$("$package" init bash 2>/dev/null)"
      fi

      # If the command produced output, evaluate it in current shell
      if [[ -n "$output" ]]; then
        eval "$output"
      fi
    fi
  done
}

# run initialization
eval_packages