diff --git a/bash-helper.sh b/bash-helper.sh index 91e5ea4..432c26f 100755 --- a/bash-helper.sh +++ b/bash-helper.sh @@ -932,10 +932,19 @@ if [ "$INTERACTIVE" = true ]; then # Format commands for display: description on left, syntax on right # Get terminal width for proper alignment TERM_WIDTH=$(tput cols 2>/dev/null || echo 120) - SYNTAX_WIDTH=50 - DESC_WIDTH=$((TERM_WIDTH - SYNTAX_WIDTH - 5)) - # Format each command with right-aligned syntax + # Calculate widths (leave room for colors and spacing) + MAX_CMD_WIDTH=15 + SYNTAX_WIDTH=45 + DESC_WIDTH=$((TERM_WIDTH - MAX_CMD_WIDTH - SYNTAX_WIDTH - 10)) + + # Ensure minimum widths + if [ $DESC_WIDTH -lt 30 ]; then + DESC_WIDTH=30 + SYNTAX_WIDTH=$((TERM_WIDTH - MAX_CMD_WIDTH - DESC_WIDTH - 10)) + fi + + # Format each command with colors and right-aligned syntax FORMATTED_COMMANDS=() for cmd in "${COMMANDS[@]}"; do CMD_NAME=${cmd%%:*} @@ -950,7 +959,7 @@ if [ "$INTERACTIVE" = true ]; then SYNTAX_PART="$CMD_NAME [options]" fi - # Truncate if too long + # Truncate if too long (accounting for actual content, not color codes) if [ ${#DESC_PART} -gt $DESC_WIDTH ]; then DESC_PART="${DESC_PART:0:$((DESC_WIDTH-3))}..." fi @@ -958,23 +967,42 @@ if [ "$INTERACTIVE" = true ]; then SYNTAX_PART="${SYNTAX_PART:0:$((SYNTAX_WIDTH-3))}..." fi - # Format with padding - printf -v formatted_line "%-${DESC_WIDTH}s %${SYNTAX_WIDTH}s" "$CMD_NAME:$DESC_PART" "$SYNTAX_PART" + # Calculate padding for right-alignment of syntax + # Total visible length = cmd_name + ": " + desc + spaces + syntax + CMD_LEN=${#CMD_NAME} + DESC_LEN=${#DESC_PART} + SYNTAX_LEN=${#SYNTAX_PART} + NEEDED_SPACES=$((TERM_WIDTH - CMD_LEN - 2 - DESC_LEN - SYNTAX_LEN - 5)) + + # Ensure at least 2 spaces + if [ $NEEDED_SPACES -lt 2 ]; then + NEEDED_SPACES=2 + fi + + # Create spacing string + SPACES=$(printf '%*s' "$NEEDED_SPACES" '') + + # Format with colors: + # - Cyan for command name + # - White for description + # - Dim cyan for syntax + formatted_line="\033[0;36m${CMD_NAME}\033[0m: ${DESC_PART}${SPACES}\033[2;36m${SYNTAX_PART}\033[0m" + FORMATTED_COMMANDS+=("$formatted_line") done # Show in fzf with formatted display - SELECTED=$(printf "%s\n" "${FORMATTED_COMMANDS[@]}" | fzf \ + SELECTED=$(printf "%b\n" "${FORMATTED_COMMANDS[@]}" | fzf \ --height 60% \ --border \ - --header "Select a command (description | syntax)" \ + --header "Select a command (cyan: command | description | dim: syntax)" \ --prompt "🔍 Search: " \ --preview-window=hidden \ --ansi) if [ -n "$SELECTED" ]; then - # Extract command name from selection - CMD=$(echo "$SELECTED" | awk -F: '{print $1}') + # Extract command name from selection (strip color codes) + CMD=$(echo "$SELECTED" | sed 's/\x1b\[[0-9;]*m//g' | awk -F: '{print $1}' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//') # Find the original command entry to get full details for cmd in "${COMMANDS[@]}"; do