Skip to content

Commit 30c74fb

Browse files
auto suggest package command
1 parent 7526337 commit 30c74fb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/plugins/terminal/scripts/init-alpine.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export HOME=/home
77
export TERM=xterm-256color
88

99

10-
required_packages="bash"
10+
required_packages="bash command-not-found"
1111
missing_packages=""
1212

1313
for pkg in $required_packages; do
@@ -79,6 +79,24 @@ if [ -s /etc/acode_motd ]; then
7979
cat /etc/acode_motd
8080
fi
8181
82+
command_not_found_handle() {
83+
local cmd="$1"
84+
local pkg
85+
local green="\033[1;32m"
86+
local reset="\033[0m"
87+
88+
# Search for package providing the command
89+
pkg=$(apk search -x "cmd:$cmd" 2>/dev/null | awk -F'-[0-9]' '{print $1}' | head -n 1)
90+
91+
if [ -n "$pkg" ]; then
92+
printf "The program %s is not installed. Install it by executing:\n ${green}apk add %s${reset}\n" "$cmd" "$pkg" >&2
93+
else
94+
printf "The program %s is not installed and no package provides it.\n" "$cmd" >&2
95+
fi
96+
97+
return 127
98+
}
99+
82100
EOF
83101
fi
84102

0 commit comments

Comments
 (0)