Files
ps1-craft/ps1.sh
2026-01-24 02:34:44 +00:00

60 lines
1.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# -------------------------------------------------
# ps1.sh custom PS1 (must be sourced)
# -------------------------------------------------
# Must be sourced, not executed
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "Dette scriptet må kjøres med:"
echo " source ps1.sh"
echo "eller:"
echo " . ps1.sh"
exit 1
fi
# Only for interactive shells
case "$-" in
*i*) ;;
*) return 0 ;;
esac
# -------------------------------------------------
# Emoji helper
# -------------------------------------------------
_ps1_emoji() {
local emojis=( "🚀" "✨" "🔥" "🧠" "🛠️" )
printf '%s' "${emojis[RANDOM % ${#emojis[@]}]}"
}
# -------------------------------------------------
# Build PS1 (your requested order)
# -------------------------------------------------
_ps1_build() {
local emoji="$(_ps1_emoji)"
printf '%b' \
"\[\e[31m\]\d\[\e[0m\] \
\[\e[33m\]\A\[\e[0m\] \
\[\e[34m\]\u@\h\[\e[0m\] \
\[\e[32m\]\w\[\e[0m\]\n\\$emoji "
}
# -------------------------------------------------
# PROMPT_COMMAND handling
# -------------------------------------------------
__PS1_PREV_PROMPT_COMMAND="${PROMPT_COMMAND-}"
ps1_on() {
PROMPT_COMMAND='_PS1="$(_ps1_build)"; export PS1="$_PS1"'
_PS1="$(_ps1_build)"; export PS1="$_PS1"
}
ps1_off() {
PROMPT_COMMAND="$__PS1_PREV_PROMPT_COMMAND"
}
# -------------------------------------------------
# End of file
# -------------------------------------------------