Skip to content

Commit cb91a15

Browse files
fix: init-alpine
1 parent 85eb76e commit cb91a15

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

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

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,50 +59,63 @@ EOF
5959
fi
6060

6161
# Create initrc if it doesn't exist
62-
if [ ! -e "$PREFIX/alpine/initrc" ]; then
63-
cat <<EOF > "$PREFIX/alpine/initrc"
64-
if [[ -f ~/.bashrc ]]; then
65-
source ~/.bashrc
62+
#initrc runs in bash so we can use bash features
63+
if [ ! -e "$PREFIX/alpine/initrc" ]; then
64+
cat <<'EOF' > "$PREFIX/alpine/initrc"
65+
# Source rc files if they exist
66+
67+
if [ -f "/etc/profile" ]; then
68+
source "/etc/profile"
69+
fi
70+
71+
72+
if [ -f "$HOME/.bashrc" ]; then
73+
source "$HOME/.bashrc"
6674
fi
6775
68-
if [[ -f /etc/bash/bashrc ]]; then
76+
if [ -f /etc/bash/bashrc ]; then
6977
source /etc/bash/bashrc
7078
fi
7179
72-
export PATH=\$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/share/bin:/usr/share/sbin:/usr/local/bin:/usr/local/sbin
73-
export HOME=/home
74-
export TERM=xterm-256color
75-
export SHELL=\$(command -v bash)
76-
export PIP_BREAK_SYSTEM_PACKAGES=1
80+
# Environment setup
81+
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/share/bin:/usr/share/sbin:/usr/local/bin:/usr/local/sbin
82+
export PATH HOME=/home TERM=xterm-256color SHELL=/bin/sh PIP_BREAK_SYSTEM_PACKAGES=1
7783
84+
# Display MOTD if available
7885
if [ -s /etc/acode_motd ]; then
7986
cat /etc/acode_motd
8087
fi
8188
89+
# Command-not-found handler
8290
command_not_found_handle() {
83-
local cmd="$1"
84-
local pkg
85-
local green="\033[1;32m"
86-
local reset="\033[0m"
91+
cmd="$1"
92+
pkg=""
93+
green="\033[1;32m"
94+
reset="\033[0m"
8795
88-
# Search for package providing the command
8996
pkg=$(apk search -x "cmd:$cmd" 2>/dev/null | awk -F'-[0-9]' '{print $1}' | head -n 1)
9097
9198
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
99+
printf "The program '%s' is not installed.\nInstall it by executing:\n %sapk add %s%s\n" "$cmd" "$green" "$pkg" "$reset" >&2
93100
else
94-
printf "The program %s is not installed and no package provides it.\n" "$cmd" >&2
101+
printf "The program '%s' is not installed and no package provides it.\n" "$cmd" >&2
95102
fi
96103
97104
return 127
98105
}
99-
100106
EOF
101-
fi
107+
fi
108+
109+
# Add PS1 only if not already present
110+
if ! grep -q 'PS1=' "$PREFIX/alpine/initrc"; then
111+
echo 'PS1="\033[1;32m\u\033[0m@localhost \w \$ "' >> "$PREFIX/alpine/initrc"
112+
fi
113+
114+
chmod +x "$PREFIX/alpine/initrc"
115+
116+
#actual souce
117+
"$PREFIX/axs" -c "sh --rcfile /initrc -i"
102118

103-
echo 'export PS1="\[\e[38;5;46m\]\u\[\e[0m\]@localhost \[\e[0m\]\w \[\e[0m\]\\$ "' >> $PREFIX/alpine/initrc
104-
chmod +x "$PREFIX/alpine/initrc"
105-
"$PREFIX/axs" -c "bash --rcfile /initrc -i"
106119
else
107120
exec "$@"
108121
fi

0 commit comments

Comments
 (0)