Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/plugins/terminal/scripts/init-alpine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,39 @@ export TERM=xterm-256color
SHELL=/bin/bash
export PIP_BREAK_SYSTEM_PACKAGES=1

# Smart path shortening function (fish-style: ~/p/s/components)
_shorten_path() {
local path="$PWD"

if [[ "$HOME" != "/" && "$path" == "$HOME" ]]; then
echo "~"
return
elif [[ "$HOME" != "/" && "$path" == "$HOME/"* ]]; then
path="~${path#$HOME}"
fi

[[ "$path" == "~" ]] && echo "~" && return

local parts result=""
IFS='/' read -ra parts <<< "$path"
local len=${#parts[@]}

for ((i=0; i<len; i++)); do
[[ -z "${parts[i]}" ]] && continue
if [[ $i -lt $((len-1)) ]]; then
result+="${parts[i]:0:1}/"
else
result+="${parts[i]}"
fi
done

[[ "$path" == /* ]] && echo "/$result" || echo "$result"
}

# Update prompt vars before each command
PROMPT_COMMAND='_PS1_PATH=$(_shorten_path); _PS1_EXIT=$?'


# Display MOTD if available
if [ -s /etc/acode_motd ]; then
cat /etc/acode_motd
Expand Down Expand Up @@ -120,12 +153,15 @@ fi

# Add PS1 only if not already present
if ! grep -q 'PS1=' "$PREFIX/alpine/initrc"; then
echo 'PS1="\[\033[1;32m\]\u\[\033[0m\]@localhost \w \$ "' >> "$PREFIX/alpine/initrc"
# Smart path shortening (fish-style: ~/p/s/components)
echo 'PS1="\[\033[1;32m\]\u\[\033[0m\]@localhost \[\033[1;34m\]\$_PS1_PATH\[\033[0m\] \[\$([ \$_PS1_EXIT -ne 0 ] && echo \"\033[31m\")\]\$\[\033[0m\] "' >> "$PREFIX/alpine/initrc"
# Simple prompt (uncomment below and comment above if you prefer full paths)
# echo 'PS1="\[\033[1;32m\]\u\[\033[0m\]@localhost \[\033[1;34m\]\w\[\033[0m\] \$ "' >> "$PREFIX/alpine/initrc"
fi

chmod +x "$PREFIX/alpine/initrc"

#actual souce
#actual source
#everytime a terminal is started initrc will run
"$PREFIX/axs" -c "bash --rcfile /initrc -i"

Expand Down