summaryrefslogtreecommitdiff
path: root/scripts/pkg-install
blob: b86e803930a4bcef49971d972093f378733b9c16 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash

set -euo pipefail

# Colors
RED='\e[31m'
GREEN='\e[32m'
YELLOW='\e[33m'
BLUE='\e[34m'
BOLD='\e[1m'
RESET='\e[0m'

# Check required tools
for tool in fzf pacman; do
  if ! command -v "$tool" >/dev/null 2>&1; then
    echo -e "${RED}Error: $tool is not installed${RESET}"
    notify-send "ERROR" "$tool is not installed."
    exit 1
  fi
done

# FZF configuration
fzf_args=(
  --multi
  --preview 'pacman -Sii {1}'
  --preview-label-pos='bottom'
  --preview-window 'down:65%:wrap'
  --color 'pointer:green,marker:green'
  --header='Select packages to install (TAB to select multiple, ENTER to confirm)'
  --border
)

echo -e "${BLUE}${BOLD}Loading package list...${RESET}\n"

# Get package selections
pkg_names=$(pacman -Slq | fzf "${fzf_args[@]}" || true)

# Check if user selected anything
if [[ -z "$pkg_names" ]]; then
  echo -e "${YELLOW}No packages selected. Exiting.${RESET}"
  exit 0
fi

# Show what will be installed
echo -e "${BLUE}${BOLD}Selected packages:${RESET}"
echo "$pkg_names" | sed 's/^/  - /'
echo

# Convert to array for safe handling
mapfile -t packages < <(echo "$pkg_names")

# Install packages
echo -e "${GREEN}${BOLD}Installing ${#packages[@]} package(s)...${RESET}\n"

if sudo pacman -S --noconfirm "${packages[@]}"; then
  echo
  echo -e "${GREEN}${BOLD}✓ Successfully installed ${#packages[@]} package(s)${RESET}"
else
  echo
  echo -e "${RED}${BOLD}✗ Installation failed or was incomplete${RESET}"
fi

echo

# Keep window open
if command -v gum >/dev/null 2>&1; then
  gum spin --spinner "globe" --title "Done! Press any key to close..." -- bash -c 'read -n 1 -s'
else
  echo -e "${BLUE}Press any key to close...${RESET}"
  read -n 1 -s
fi