fix(boot): PS1 bruker kun lokal SHA (ikke remote) + legg til ls alias
This commit is contained in:
parent
9cebc3a95e
commit
a16d1dabfd
|
|
@ -41,6 +41,8 @@ alias mirror-sync='bash ~/OSVauco/scripts/sync-gdrive-mirror.sh'
|
|||
alias cost-audit='bash ~/OSVauco/scripts/cost-audit.sh'
|
||||
alias roadmap='cat ~/OSVauco/docs/VAUCO_OS_ROADMAP.md'
|
||||
alias session-log='cat ~/OSVauco/docs/OSVAUCO_OPAX_SESSION_LOG.md'
|
||||
alias l='ls -la --color=auto'
|
||||
alias ll='ls -lh --color=auto'
|
||||
ALIASES
|
||||
_ALIAS_INJECTED=true
|
||||
else
|
||||
|
|
@ -54,6 +56,8 @@ alias mirror-sync='bash ~/OSVauco/scripts/sync-gdrive-mirror.sh'
|
|||
alias cost-audit='bash ~/OSVauco/scripts/cost-audit.sh'
|
||||
alias roadmap='cat ~/OSVauco/docs/VAUCO_OS_ROADMAP.md'
|
||||
alias session-log='cat ~/OSVauco/docs/OSVAUCO_OPAX_SESSION_LOG.md'
|
||||
alias l='ls -la --color=auto'
|
||||
alias ll='ls -lh --color=auto'
|
||||
|
||||
# =============================================================================
|
||||
# PROMPT_COMMAND — logger + PS1-statusindikator
|
||||
|
|
@ -65,27 +69,26 @@ export OSVAUCO_DIR="$OSVAUCO_DIR"
|
|||
_opax_last_cmd=''
|
||||
trap '_opax_last_cmd=$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//")' DEBUG
|
||||
|
||||
# Beregn OSVauco-status for PS1 (kjører raskt, ingen nettverkskall)
|
||||
# PS1-status: kun lokale sjekker — ingen nettverkskall
|
||||
# Grønn = gcloud OK + GDrive mirror er i sync med lokal HEAD
|
||||
# Gul = GDrive mirror utdatert (kjør mirror-sync)
|
||||
# Rød = gcloud auth utløpt
|
||||
_opax_ps1_status() {
|
||||
local state=0 # 0=OK, 1=warn, 2=fail
|
||||
local state=0
|
||||
|
||||
# Auth: gcloud
|
||||
if ! gcloud auth print-access-token >/dev/null 2>&1; then state=2; fi
|
||||
|
||||
# Repo sync
|
||||
local local_sha remote_sha
|
||||
local_sha=$(git -C "$OSVAUCO_DIR" rev-parse --short HEAD 2>/dev/null || echo "")
|
||||
remote_sha=$(git -C "$OSVAUCO_DIR" ls-remote origin refs/heads/main 2>/dev/null | cut -c1-7 || echo "")
|
||||
if [[ -n "$remote_sha" && "$local_sha" != "$remote_sha" ]]; then
|
||||
[[ $state -lt 1 ]] && state=1
|
||||
# gcloud auth (rask lokal tokensjekk)
|
||||
if ! gcloud auth print-access-token >/dev/null 2>&1; then
|
||||
echo 2; return
|
||||
fi
|
||||
|
||||
# GDrive mirror
|
||||
# GDrive mirror: sammenlign LAST_SHA mot lokal HEAD
|
||||
local local_sha
|
||||
local_sha=$(git -C "$OSVAUCO_DIR" rev-parse --short HEAD 2>/dev/null || echo "")
|
||||
if [[ -f "$OSVAUCO_DIR/.gdrive-mirror-state" ]]; then
|
||||
local last_sha
|
||||
last_sha=$(grep '^LAST_SHA=' "$OSVAUCO_DIR/.gdrive-mirror-state" | cut -d= -f2-)
|
||||
if [[ "$last_sha" != "$local_sha" ]]; then
|
||||
[[ $state -lt 1 ]] && state=1
|
||||
if [[ -n "$last_sha" && "$last_sha" != "$local_sha" ]]; then
|
||||
state=1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
@ -106,32 +109,24 @@ _opax_log_cmd() {
|
|||
_opax_last_cmd=''
|
||||
}
|
||||
|
||||
# PS1: ❱ OSVauco ❱ i grønn/gul/rød + git-branch + sti + $
|
||||
# Format:
|
||||
# \n ❱ OSVauco ❱ git:(main) ~/OSVauco
|
||||
# $ _
|
||||
_opax_set_ps1() {
|
||||
local state
|
||||
state=$(_opax_ps1_status)
|
||||
|
||||
# ANSI escape-koder for PS1 (må være i \[ \] for korrekt linjelengde)
|
||||
local C_GREEN='\[\033[01;32m\]'
|
||||
local C_LGREEN='\[\033[38;5;82m\]' # lys grønn (glow-effekt)
|
||||
local C_LGREEN='\[\033[38;5;82m\]'
|
||||
local C_YELLOW='\[\033[01;33m\]'
|
||||
local C_RED='\[\033[01;31m\]'
|
||||
local C_CYAN='\[\033[01;36m\]'
|
||||
local C_DIM='\[\033[2;37m\]'
|
||||
local C_BOLD='\[\033[1m\]'
|
||||
local C_NC='\[\033[0m\]'
|
||||
|
||||
local badge_color
|
||||
case $state in
|
||||
0) badge_color="$C_LGREEN" ;; # alt OK — lys grønn
|
||||
1) badge_color="$C_YELLOW" ;; # advarsel — gul
|
||||
2) badge_color="$C_RED" ;; # feil — rød
|
||||
0) badge_color="$C_LGREEN" ;;
|
||||
1) badge_color="$C_YELLOW" ;;
|
||||
2) badge_color="$C_RED" ;;
|
||||
esac
|
||||
|
||||
# Git-branch (stille hvis ikke i repo)
|
||||
local git_info=''
|
||||
local branch
|
||||
branch=$(git -C "$OSVAUCO_DIR" branch --show-current 2>/dev/null || echo "")
|
||||
|
|
@ -143,14 +138,11 @@ _opax_set_ps1() {
|
|||
if [[ "${PROMPT_COMMAND}" != *"_opax_log_cmd"* ]]; then
|
||||
PROMPT_COMMAND="_opax_log_cmd; _opax_set_ps1${PROMPT_COMMAND:+; $PROMPT_COMMAND}"
|
||||
else
|
||||
# Legg til PS1-oppdatering hvis den mangler
|
||||
if [[ "${PROMPT_COMMAND}" != *"_opax_set_ps1"* ]]; then
|
||||
PROMPT_COMMAND="${PROMPT_COMMAND}; _opax_set_ps1"
|
||||
fi
|
||||
fi
|
||||
export PROMPT_COMMAND
|
||||
|
||||
# Sett PS1 umiddelbart ved boot
|
||||
_opax_set_ps1
|
||||
|
||||
# =============================================================================
|
||||
|
|
@ -370,6 +362,8 @@ printf " ${DIM}roadmap${NC} → cat docs/VAUCO_OS_ROADMAP.md\n"
|
|||
printf " ${DIM}session-log${NC} → cat docs/OSVAUCO_OPAX_SESSION_LOG.md\n"
|
||||
printf " ${DIM}mirror-sync${NC} → bash scripts/sync-gdrive-mirror.sh\n"
|
||||
printf " ${DIM}opax-logg-slutt${NC} → avslutt og loggfør session\n"
|
||||
printf " ${DIM}l${NC} → ls -la --color=auto\n"
|
||||
printf " ${DIM}ll${NC} → ls -lh --color=auto\n"
|
||||
printf "${DIM} ---------------------------------------------------${NC}\n\n"
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user