Skip to content

Right-aligned segments need terminal width detection for fill module #2

@mariusvniekerk

Description

@mariusvniekerk

Problem

When using $fill in the starship config to right-align segments (e.g. model/context/cost on the right), starship defaults to 80 columns because the Claude Code statusline subprocess doesn't have a real TTY attached. This means the fill module doesn't push content to the actual right edge.

Workaround

Detect the real terminal width via the parent process's TTY and pass it to starship with -w:

# Detect real terminal width via parent process TTY
term_width=""
parent_tty="$(ps -o tty= -p "$(ps -o ppid= -p $$)" 2>/dev/null | tr -d ' ')"
if [ -n "$parent_tty" ] && [ "$parent_tty" != "??" ] && [ "$parent_tty" != "?" ]; then
  w="$(stty size < "/dev/$parent_tty" 2>/dev/null | awk '{print $2}')"
  if [ -n "$w" ] && [ "$w" -gt 0 ] 2>/dev/null; then
    term_width=$((w - 6))
  fi
fi

Then pass -w $term_width to starship prompt if set.

This technique is borrowed from ccstatusline which uses the same parent TTY approach.

Example config with fill

format = """
$directory \
$git_branch$git_status\
$fill\
${env_var.CLAUDE_MODEL_NERD} \
${env_var.CLAUDE_CONTEXT} \
${env_var.CLAUDE_COST}\
"""

[fill]
symbol = " "

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions