fjerne utf-8
This commit is contained in:
76
ps1.sh
76
ps1.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Must be sourced, not executed
|
# Must be sourced
|
||||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||||
echo "Bruk: source ps1.sh"
|
echo "Bruk: source ps1.sh"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -11,15 +11,9 @@ case "$-" in
|
|||||||
*) return 0 ;;
|
*) return 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Returns 0 if current shell locale is UTF-8 capable
|
# -------------------------------------------------
|
||||||
_ps1_is_utf8() {
|
# Emoji / symbol based on time (Europe/Oslo)
|
||||||
# locale charmap outputs e.g. UTF-8
|
# -------------------------------------------------
|
||||||
local cm
|
|
||||||
cm="$(LC_ALL=${LC_ALL-} LANG=${LANG-} locale charmap 2>/dev/null || true)"
|
|
||||||
[[ "$cm" == "UTF-8" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Emoji based on time (Europe/Oslo) with ASCII fallback if not UTF-8
|
|
||||||
_ps1_symbol() {
|
_ps1_symbol() {
|
||||||
local hh mm h m
|
local hh mm h m
|
||||||
hh="$(TZ=Europe/Oslo date +%H)"
|
hh="$(TZ=Europe/Oslo date +%H)"
|
||||||
@@ -27,65 +21,53 @@ _ps1_symbol() {
|
|||||||
h=$((10#$hh))
|
h=$((10#$hh))
|
||||||
m=$((10#$mm))
|
m=$((10#$mm))
|
||||||
|
|
||||||
if _ps1_is_utf8; then
|
if (( h >= 5 && h <= 8 )); then
|
||||||
if (( h >= 5 && h <= 8 )); then
|
printf '%s' "🌅"
|
||||||
printf '%s' "🌅"
|
elif (( h >= 9 && h <= 10 )); then
|
||||||
elif (( h >= 9 && h <= 10 )); then
|
printf '%s' "☕"
|
||||||
printf '%s' "☕"
|
elif (( h == 11 && m < 30 )); then
|
||||||
elif (( h == 11 && m < 30 )); then
|
printf '%s' "🥪"
|
||||||
printf '%s' "🥪"
|
elif (( (h == 11 && m >= 30) || (h >= 12 && h <= 15) )); then
|
||||||
elif (( (h == 11 && m >= 30) || (h >= 12 && h <= 15) )); then
|
printf '%s' "💻"
|
||||||
printf '%s' "💻"
|
elif (( h == 16 )); then
|
||||||
elif (( h == 16 )); then
|
printf '%s' "🍲"
|
||||||
printf '%s' "🍲"
|
elif (( h >= 17 && h <= 22 )); then
|
||||||
elif (( h >= 17 && h <= 22 )); then
|
printf '%s' "🌆"
|
||||||
printf '%s' "🌆"
|
|
||||||
else
|
|
||||||
printf '%s' "🌙"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# ASCII fallbacks
|
printf '%s' "🌙"
|
||||||
if (( h >= 5 && h <= 8 )); then
|
|
||||||
printf '%s' "^" # early
|
|
||||||
elif (( h >= 9 && h <= 10 )); then
|
|
||||||
printf '%s' "o" # morning
|
|
||||||
elif (( h == 11 && m < 30 )); then
|
|
||||||
printf '%s' "=" # lunch
|
|
||||||
elif (( (h == 11 && m >= 30) || (h >= 12 && h <= 15) )); then
|
|
||||||
printf '%s' "*" # day
|
|
||||||
elif (( h == 16 )); then
|
|
||||||
printf '%s' "#" # dinner
|
|
||||||
elif (( h >= 17 && h <= 22 )); then
|
|
||||||
printf '%s' "~" # evening
|
|
||||||
else
|
|
||||||
printf '%s' "." # night
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# -------------------------------------------------
|
||||||
|
# Build PS1
|
||||||
|
# -------------------------------------------------
|
||||||
_ps1_build() {
|
_ps1_build() {
|
||||||
local sym path
|
local sym path
|
||||||
sym="$(_ps1_symbol)"
|
sym="$(_ps1_symbol)"
|
||||||
path="$(pwd)"
|
path="$(pwd)"
|
||||||
|
|
||||||
# Pastel-ish 256 colors
|
|
||||||
local BOX="\[\e[38;5;183m\]"
|
local BOX="\[\e[38;5;183m\]"
|
||||||
local VAL="\[\e[38;5;117m\]"
|
local VAL="\[\e[38;5;117m\]"
|
||||||
local ACC="\[\e[38;5;229m\]"
|
local ACC="\[\e[38;5;229m\]"
|
||||||
local RST="\[\e[0m\]"
|
local RST="\[\e[0m\]"
|
||||||
|
|
||||||
# IMPORTANT: keep PS1 escapes as \\d \\A \\u \\h \\n
|
# NOTE:
|
||||||
|
# - PS1 escapes must be \\d \\A \\u \\h \\n
|
||||||
|
# - NO $variables inside PS1 (PS1 re-parses $)
|
||||||
local ps1
|
local ps1
|
||||||
ps1="${BOX}╭─(${ACC}\\d${BOX} ${ACC}\\A${BOX})-(${VAL}\\u${BOX}@${VAL}\\h${BOX})-(${VAL}${path}${BOX})${RST}\\n${BOX}╰──➜ ${RST}\\$${sym} "
|
ps1="${BOX}╭─(${ACC}\\d${BOX} ${ACC}\\A${BOX})-(${VAL}\\u${BOX}@${VAL}\\h${BOX})-(${VAL}${path}${BOX})${RST}\\n${BOX}╰──➜ ${RST}\\$ ${sym} "
|
||||||
|
|
||||||
printf '%s' "$ps1"
|
printf '%s' "$ps1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# -------------------------------------------------
|
||||||
|
# Enable / disable
|
||||||
|
# -------------------------------------------------
|
||||||
__PS1_PREV_PROMPT_COMMAND="${PROMPT_COMMAND-}"
|
__PS1_PREV_PROMPT_COMMAND="${PROMPT_COMMAND-}"
|
||||||
|
|
||||||
ps1_on() {
|
ps1_on() {
|
||||||
PROMPT_COMMAND='_PS1="$(_ps1_build)"; export PS1="$_PS1"'
|
PROMPT_COMMAND='_PS1="$(_ps1_build)"; PS1="$_PS1"'
|
||||||
_PS1="$(_ps1_build)"; export PS1="$_PS1"
|
PS1="$(_ps1_build)"
|
||||||
}
|
}
|
||||||
|
|
||||||
ps1_off() {
|
ps1_off() {
|
||||||
|
|||||||
Reference in New Issue
Block a user