# Generated by Powerlevel10k configuration wizard on 2025-08-12 at 19:45 CDT.
# Based on romkatv/powerlevel10k/config/p10k-pure.zsh, checksum 7533.
# Wizard options: nerdfont-v3 + powerline, small icons, pure, snazzy, rprompt, 12h time,
# 1 line, sparse, transient_prompt, instant_prompt=verbose.
# Type `p10k configure` to generate another config.
#
# Config file for Powerlevel10k with the style of Pure (https://github.com/sindresorhus/pure).
#
# Differences from Pure:
#
#   - Git:
#     - `@c4d3ec2c` instead of something like `v1.4.0~11` when in detached HEAD state.
#     - No automatic `git fetch` (the same as in Pure with `PURE_GIT_PULL=0`).
#
# Apart from the differences listed above, the replication of Pure prompt is exact. This includes
# even the questionable parts. For example, just like in Pure, there is no indication of Git status
# being stale; prompt symbol is the same in command, visual and overwrite vi modes; when prompt
# doesn't fit on one line, it wraps around with no attempt to shorten it.
#
# If you like the general style of Pure but not particularly attached to all its quirks, type
# `p10k configure` and pick "Lean" style. This will give you slick minimalist prompt while taking
# advantage of Powerlevel10k features that aren't present in Pure.

# Temporarily change options.
'builtin' 'local' '-a' 'p10k_config_opts'
[[ ! -o 'aliases'         ]] || p10k_config_opts+=('aliases')
[[ ! -o 'sh_glob'         ]] || p10k_config_opts+=('sh_glob')
[[ ! -o 'no_brace_expand' ]] || p10k_config_opts+=('no_brace_expand')
'builtin' 'setopt' 'no_aliases' 'no_sh_glob' 'brace_expand'

() {
  emulate -L zsh -o extended_glob

  # Unset all configuration options.
  unset -m '(POWERLEVEL9K_*|DEFAULT_USER)~POWERLEVEL9K_GITSTATUS_DIR'

  # Zsh >= 5.1 is required.
  [[ $ZSH_VERSION == (5.<1->*|<6->.*) ]] || return

  # Prompt colors.
  local grey='242'
  local red='#FF5C57'
  local yellow='#F3F99D'
  local blue='#57C7FF'
  local magenta='#FF6AC1'
  local cyan='#9AEDFE'
  local white='#F1F1F0'

  # Define custom segments using P10k's custom segment feature
  typeset -g POWERLEVEL9K_CUSTOM_JJ_VCS="prompt_custom_vcs"
  typeset -g POWERLEVEL9K_CUSTOM_JJ_VCS_FOREGROUND=208  # Orange for JJ
  typeset -g POWERLEVEL9K_CUSTOM_JJ_VCS_BACKGROUND=''
  
  typeset -g POWERLEVEL9K_CUSTOM_TODO="prompt_todo"
  typeset -g POWERLEVEL9K_CUSTOM_TODO_FOREGROUND=$cyan
  typeset -g POWERLEVEL9K_CUSTOM_TODO_BACKGROUND=''
  
  typeset -g POWERLEVEL9K_CUSTOM_NEXTFLOW="prompt_nextflow"
  typeset -g POWERLEVEL9K_CUSTOM_NEXTFLOW_FOREGROUND=$blue  # Blue for workflow tool
  typeset -g POWERLEVEL9K_CUSTOM_NEXTFLOW_BACKGROUND=''
  typeset -g POWERLEVEL9K_CUSTOM_NEXTFLOW_SHOW_ON_COMMAND='nextflow|nf'
  
  # Left prompt segments.
  typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
    # context                 # user@host
    dir                       # current directory
    custom_jj_vcs             # jj or git status (custom)
    nix_shell                 # nix development environment
    virtualenv                # python virtual environment
    node_version              # node.js version for projects
    custom_nextflow           # nextflow version for projects
    package                   # package.json version
    terraform                 # terraform workspace
    aws                       # aws profile
    docker_machine            # docker context
    status                    # exit code (only on error)
    prompt_char               # prompt symbol
  )

  # Right prompt segments.
  typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
    custom_jj_desc            # jj description (show on command)
    custom_todo               # todo.txt task count
    command_execution_time    # previous command duration
    python_version            # python version
    background_jobs           # running background jobs
    context                   # user@host
    time                      # current time
  )

  # Basic style options that define the overall prompt look.
  typeset -g POWERLEVEL9K_BACKGROUND=                            # transparent background
  typeset -g POWERLEVEL9K_{LEFT,RIGHT}_{LEFT,RIGHT}_WHITESPACE=  # no surrounding whitespace
  typeset -g POWERLEVEL9K_{LEFT,RIGHT}_SUBSEGMENT_SEPARATOR=' '  # separate segments with a space
  typeset -g POWERLEVEL9K_{LEFT,RIGHT}_SEGMENT_SEPARATOR=        # no end-of-line symbol
  # Enable minimal visual identifiers for better context
  typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION='${P9K_VISUAL_IDENTIFIER}'

  # Add an empty line before each prompt except the first. Enhanced for lean style.
  typeset -g POWERLEVEL9K_PROMPT_ADD_NEWLINE=true

  # Lean style prompt characters with enhanced visual feedback
  # Magenta prompt symbol if the last command succeeded.
  typeset -g POWERLEVEL9K_PROMPT_CHAR_OK_{VIINS,VICMD,VIVIS}_FOREGROUND=$magenta
  # Red prompt symbol if the last command failed.
  typeset -g POWERLEVEL9K_PROMPT_CHAR_ERROR_{VIINS,VICMD,VIVIS}_FOREGROUND=$red
  # Default prompt symbol - lean style uses cleaner chevron
  typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIINS_CONTENT_EXPANSION='❯'
  # Prompt symbol in command vi mode.
  typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VICMD_CONTENT_EXPANSION='❮'
  # Prompt symbol in visual vi mode is the same as in command mode.
  typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIVIS_CONTENT_EXPANSION='❮'
  # Prompt symbol in overwrite vi mode is the same as in command mode.
  typeset -g POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE=false
  # Lean enhancement: show different symbols for different vi modes
  typeset -g POWERLEVEL9K_PROMPT_CHAR_LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL=''

  # ==[ DEVELOPER ENHANCEMENTS ]==
  
  # Transient prompt - makes previous prompts minimal (super clean!)
  typeset -g POWERLEVEL9K_TRANSIENT_PROMPT=always
  
  # Nix Shell - show when in nix development environment
  typeset -g POWERLEVEL9K_NIX_SHELL_FOREGROUND=$cyan
  typeset -g POWERLEVEL9K_NIX_SHELL_CONTENT_EXPANSION='${P9K_NIX_SHELL_NAME}'
  
  # Python Virtual Environment - enhanced styling
  typeset -g POWERLEVEL9K_VIRTUALENV_FOREGROUND=$yellow
  typeset -g POWERLEVEL9K_VIRTUALENV_SHOW_WITH_PYENV=false
  typeset -g POWERLEVEL9K_VIRTUALENV_{LEFT,RIGHT}_DELIMITER=
  
  # Python Version - show python version for projects
  typeset -g POWERLEVEL9K_PYTHON_VERSION_FOREGROUND=$blue
  typeset -g POWERLEVEL9K_PYTHON_VERSION_PROJECT_ONLY=true
  
  # Node Version - show for Node.js projects only
  typeset -g POWERLEVEL9K_NODE_VERSION_FOREGROUND=$cyan
  typeset -g POWERLEVEL9K_NODE_VERSION_PROJECT_ONLY=true
  
  # Package Version - show package.json version
  typeset -g POWERLEVEL9K_PACKAGE_FOREGROUND=$magenta
  
  # Status - only show exit code on error
  typeset -g POWERLEVEL9K_STATUS_OK=false
  typeset -g POWERLEVEL9K_STATUS_ERROR_FOREGROUND=$red
  
  # Background Jobs - show running jobs
  typeset -g POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND=$yellow
  
  # Enhanced Git - more detailed git information
  typeset -g POWERLEVEL9K_VCS_STAGED_ICON='✚'
  typeset -g POWERLEVEL9K_VCS_UNSTAGED_ICON='●'
  typeset -g POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
  typeset -g POWERLEVEL9K_VCS_CONFLICTED_ICON='✖'
  typeset -g POWERLEVEL9K_VCS_COMMITS_AHEAD_ICON='⬆'
  typeset -g POWERLEVEL9K_VCS_COMMITS_BEHIND_ICON='⬇'
  
  # Command Execution Time - enhanced formatting
  typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=1
  typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=2
  typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT='d h m s'
  typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND=$yellow
  
  # Directory - show more context for development
  typeset -g POWERLEVEL9K_SHORTEN_STRATEGY=truncate_to_unique
  typeset -g POWERLEVEL9K_SHORTEN_DIR_LENGTH=3
  typeset -g POWERLEVEL9K_DIR_SHOW_WRITABLE=v3
  
  # AWS - show current AWS profile
  typeset -g POWERLEVEL9K_AWS_FOREGROUND=$yellow
  typeset -g POWERLEVEL9K_AWS_CONTENT_EXPANSION='${P9K_AWS_PROFILE//\%/%%}'
  
  # Terraform - show terraform workspace
  typeset -g POWERLEVEL9K_TERRAFORM_FOREGROUND=$magenta
  typeset -g POWERLEVEL9K_TERRAFORM_CONTENT_EXPANSION='${P9K_TERRAFORM_WORKSPACE//\%/%%}'
  
  # Docker Machine - show docker context
  typeset -g POWERLEVEL9K_DOCKER_MACHINE_FOREGROUND=$blue
  typeset -g POWERLEVEL9K_DOCKER_MACHINE_CONTENT_EXPANSION='${P9K_DOCKER_MACHINE_NAME//\%/%%}'
  
  # Custom segment icons for better visual context
  typeset -g POWERLEVEL9K_AWS_VISUAL_IDENTIFIER_EXPANSION='☁️'
  typeset -g POWERLEVEL9K_TERRAFORM_VISUAL_IDENTIFIER_EXPANSION='🏗️'
  typeset -g POWERLEVEL9K_DOCKER_MACHINE_VISUAL_IDENTIFIER_EXPANSION='🐳'
  typeset -g POWERLEVEL9K_NIX_SHELL_VISUAL_IDENTIFIER_EXPANSION='❄️'
  typeset -g POWERLEVEL9K_VIRTUALENV_VISUAL_IDENTIFIER_EXPANSION='🐍'
  typeset -g POWERLEVEL9K_NODE_VERSION_VISUAL_IDENTIFIER_EXPANSION='⬢'
  typeset -g POWERLEVEL9K_PYTHON_VERSION_VISUAL_IDENTIFIER_EXPANSION='🐍'
  typeset -g POWERLEVEL9K_PACKAGE_VISUAL_IDENTIFIER_EXPANSION='📦'
  typeset -g POWERLEVEL9K_BACKGROUND_JOBS_VISUAL_IDENTIFIER_EXPANSION='⚙️'

  # Don't show Python version in virtualenv (we have separate python_version segment)
  typeset -g POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION=false

  # Blue current directory.
  typeset -g POWERLEVEL9K_DIR_FOREGROUND=$blue

  # Context format when root: user@host. The first part white, the rest grey.
  typeset -g POWERLEVEL9K_CONTEXT_ROOT_TEMPLATE="%F{$white}%n%f%F{$grey}@%m%f"
  # Context format when not root: user@host. The whole thing grey.
  typeset -g POWERLEVEL9K_CONTEXT_TEMPLATE="%F{$grey}%n@%m%f"
  # Don't show context unless root or in SSH.
  typeset -g POWERLEVEL9K_CONTEXT_{DEFAULT,SUDO}_CONTENT_EXPANSION=

  # Show previous command duration only if it's >= 5s.
  typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=5
  # Don't show fractional seconds. Thus, 7s rather than 7.3s.
  typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0
  # Duration format: 1d 2h 3m 4s.
  typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT='d h m s'
  # Yellow previous command duration.
  typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND=$yellow

  # Grey Git prompt. This makes stale prompts indistinguishable from up-to-date ones.
  typeset -g POWERLEVEL9K_VCS_FOREGROUND=$grey

  # Disable async loading indicator to make directories that aren't Git repositories
  # indistinguishable from large Git repositories without known state.
  typeset -g POWERLEVEL9K_VCS_LOADING_TEXT=

  # Don't wait for Git status even for a millisecond, so that prompt always updates
  # asynchronously when Git state changes.
  typeset -g POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS=0

  # Cyan ahead/behind arrows.
  typeset -g POWERLEVEL9K_VCS_{INCOMING,OUTGOING}_CHANGESFORMAT_FOREGROUND=$cyan
  # Don't show remote branch, current tag or stashes.
  typeset -g POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind)
  # Don't show the branch icon.
  typeset -g POWERLEVEL9K_VCS_BRANCH_ICON=
  # When in detached HEAD state, show @commit where branch normally goes.
  typeset -g POWERLEVEL9K_VCS_COMMIT_ICON='@'
  # Don't show staged, unstaged, untracked indicators.
  typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED}_ICON=
  # Show '*' when there are staged, unstaged or untracked files.
  typeset -g POWERLEVEL9K_VCS_DIRTY_ICON='*'
  # Show '⇣' if local branch is behind remote.
  typeset -g POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON=':⇣'
  # Show '⇡' if local branch is ahead of remote.
  typeset -g POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON=':⇡'
  # Don't show the number of commits next to the ahead/behind arrows.
  typeset -g POWERLEVEL9K_VCS_{COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=1
  # Remove space between '⇣' and '⇡' and all trailing spaces.
  typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION='${${${P9K_CONTENT/⇣* :⇡/⇣⇡}// }//:/ }'

  # Grey current time.
  typeset -g POWERLEVEL9K_TIME_FOREGROUND=$grey
  # Format for the current time: 09:51:02. See `man 3 strftime`.
  typeset -g POWERLEVEL9K_TIME_FORMAT='%D{%I:%M:%S %p}'
  # If set to true, time will update when you hit enter. This way prompts for the past
  # commands will contain the start times of their commands rather than the end times of
  # their preceding commands.
  typeset -g POWERLEVEL9K_TIME_UPDATE_ON_COMMAND=false

  # Transient prompt works similarly to the builtin transient_rprompt option. It trims down prompt
  # when accepting a command line. Supported values:
  #
  #   - off:      Don't change prompt when accepting a command line.
  #   - always:   Trim down prompt when accepting a command line.
  #   - same-dir: Trim down prompt when accepting a command line unless this is the first command
  #               typed after changing current working directory.
  typeset -g POWERLEVEL9K_TRANSIENT_PROMPT=always

  # Instant prompt mode.
  #
  #   - off:     Disable instant prompt. Choose this if you've tried instant prompt and found
  #              it incompatible with your zsh configuration files.
  #   - quiet:   Enable instant prompt and don't print warnings when detecting console output
  #              during zsh initialization. Choose this if you've read and understood
  #              https://github.com/romkatv/powerlevel10k#instant-prompt.
  #   - verbose: Enable instant prompt and print a warning when detecting console output during
  #              zsh initialization. Choose this if you've never tried instant prompt, haven't
  #              seen the warning, or if you are unsure what this all means.
  typeset -g POWERLEVEL9K_INSTANT_PROMPT=verbose

  # Hot reload allows you to change POWERLEVEL9K options after Powerlevel10k has been initialized.
  # For example, you can type POWERLEVEL9K_BACKGROUND=red and see your prompt turn red. Hot reload
  # can slow down prompt by 1-2 milliseconds, so it's better to keep it turned off unless you
  # really need it.
  typeset -g POWERLEVEL9K_DISABLE_HOT_RELOAD=true

  # If p10k is already loaded, reload configuration.
  # This works even with POWERLEVEL9K_DISABLE_HOT_RELOAD=true.
  (( ! $+functions[p10k] )) || p10k reload
}

# Custom todo.txt segment - shows pending task count
function prompt_todo() {
  local todo_file="${TODO_FILE:-$HOME/Documents/todo/todo.txt}"

  if [[ -f "$todo_file" ]]; then
    # Use cached count to improve performance on large todo files
    local cache_file="$XDG_CACHE_HOME/zsh/todo_count"
    local pending_count=""

    # Check if cache is newer than todo file (or less than 30 seconds old)
    if [[ -f "$cache_file" ]] && [[ "$cache_file" -nt "$todo_file" ]] ||
       [[ -f "$cache_file" && $(( $(date +%s) - $(stat -f %m "$cache_file" 2>/dev/null || echo 0) )) -lt 30 ]]; then
      pending_count=$(cat "$cache_file" 2>/dev/null)
    else
      # Update cache with current count
      pending_count=$(grep -c '^[^x]' "$todo_file" 2>/dev/null) || pending_count=0
      if [[ -n "$pending_count" ]]; then
        mkdir -p "$(dirname "$cache_file")"
        echo "$pending_count" > "$cache_file"
      fi
    fi

    if [[ $pending_count -gt 0 ]]; then
      # For P10k custom segments, just echo the output
      echo -n "✓ $pending_count"
    fi
  fi
}

# Custom Nextflow segment - shows version when in Nextflow project or typing Nextflow commands
function prompt_nextflow() {
  # Only show if in Nextflow project directory (file-based detection only)
  # P10k's SHOW_ON_COMMAND handles showing when typing nextflow commands
  if [[ -f "main.nf" ]] || [[ -f "nextflow.config" ]] || [[ -d "modules" ]] || [[ -d "workflows" ]] || [[ -n *.nf(#qN) ]]; then
    # Use cached version to avoid slow nextflow -version call (nextflow takes ~600ms!)
    local cache_file="$XDG_CACHE_HOME/zsh/nextflow_version"
    local nf_version=""

    # Check if cache exists and is newer than 24 hours
    if [[ -f "$cache_file" && $(( $(date +%s) - $(stat -f %m "$cache_file" 2>/dev/null || echo 0) )) -lt 86400 ]]; then
      nf_version=$(cat "$cache_file" 2>/dev/null)
    else
      # Async update: spawn background process to update cache
      if command -v nextflow >/dev/null 2>&1; then
        # Use existing cache immediately if available
        if [[ -f "$cache_file" ]]; then
          nf_version=$(cat "$cache_file" 2>/dev/null)
        fi

        # Update cache in background
        {
          local new_version
          new_version=$(nextflow -version 2>/dev/null | sed -n '2s/.*version \([^ ]*\).*/\1/p')
          if [[ -n "$new_version" ]]; then
            mkdir -p "$(dirname "$cache_file")"
            echo "$new_version" > "$cache_file"
          fi
        } &!
      fi
    fi

    if [[ -n "$nf_version" ]]; then
      echo -n "nf $nf_version"
    else
      # Fallback: just show "nf" if nextflow is available but no version cached yet
      if command -v nextflow >/dev/null 2>&1; then
        echo -n "nf"
      fi
    fi
  fi
}

# Custom VCS function for JJ with Git fallback
function prompt_custom_vcs() {
  # Ultra-fast version: single JJ call, no status checks
  local vcs_info

  # Try JJ first - single fast call, skip root check
  vcs_info=$(jj log -r @ --no-graph -T 'change_id.short(8)' 2>/dev/null)

  if [[ -n "$vcs_info" ]]; then
    echo -n "$vcs_info"
    return 0
  fi

  # Fall back to git - also optimized, no status check
  vcs_info=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)

  if [[ -n "$vcs_info" ]]; then
    echo -n "$vcs_info"
    return 0
  fi

  return 1
}

# JJ description function for right prompt
function prompt_jj_desc() {
  # Skip the root check for speed - just try to get description
  local jj_desc
  jj_desc=$(jj log -r @ --no-graph -T 'if(description, description.first_line().substr(0, 50), "")' 2>/dev/null)

  if [[ -n "$jj_desc" ]]; then
    echo -n "$jj_desc"
  fi
}

# Define custom JJ description segment with Show On Command
typeset -g POWERLEVEL9K_CUSTOM_JJ_DESC="prompt_jj_desc"
typeset -g POWERLEVEL9K_CUSTOM_JJ_DESC_FOREGROUND=244  # Gray color
typeset -g POWERLEVEL9K_CUSTOM_JJ_DESC_SHOW_ON_COMMAND='jj'

# Tell `p10k configure` which file it should overwrite.
typeset -g POWERLEVEL9K_CONFIG_FILE=${${(%):-%x}:a}

(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]}
'builtin' 'unset' 'p10k_config_opts'
