#!/usr/bin/env bash
# pornsh - The pornOS shell
# Very minimal but with ctrl+p integration

# Custom prompt
PS1='\[\e[0;35m\]pornOS\[\e[0m\]:\[\e[0;36m\]\w\[\e[0m\]> '

# store current terminals for ctrl+p
export PORN_TERMINAL="${PORN_TERMINAL:-/dev/tty1}"

# Bind ctrl+p to open porncli (readline macro runs the command)
if [ -t 0 ] && type bind >/dev/null 2>&1; then
    bind '"\C-p": "/usr/bin/porncli\n"' 2>/dev/null || true
fi

pornhint() {
    cat << 'EOF'
  ╔═══════════════════════════════════════════╗
  ║         WELCOME TO pornshell             ║
  ╠═══════════════════════════════════════════╣
  ║  • Press ctrl+p for porncli              ║
  ║  • Run 'proton' for system info          ║
  ║  • Run 'xvideos' for root privileges     ║
  ║  • Run 'pornpkg' for package management  ║
  ║  • Run 'porn-init' for the init system   ║
  ║  • Run 'hint' for this help              ║
  ║  • Run 'get-fucked' for fun times        ║
  ╚═══════════════════════════════════════════╝
EOF
}

proton() {
    porncli --info
}

hint() {
    pornhint
}

get-fucked() {
    echo -n "  I don't think you need my help with that. "
    read -r answer
    case "$answer" in
        y|Y|yes|YES|yeah|sure|ok|okay|fine)
            echo "  Good. At least someone's honest about it."
            ;;
        n|N|no|NO|nope)
            echo "  Denial is the first stage of grief. Fitting."
            ;;
        *)
            echo "  Ambiguous. Very pornOS of you."
            ;;
    esac
}

# display hint on first login
if [ "$PORN_HINT_SHOWN" != "yes" ]; then
    pornhint
    export PORN_HINT_SHOWN="yes"
fi

# make sure misery daemon is running
if ! pgrep -f misery-daemon > /dev/null 2>&1; then
    echo "  starting misery daemon (it's already miserable in here)..."
    misery-daemon & disown
fi

export PORN_READY="yes"
