1

How do I find the length of readline's mode string (eg @ or (cmd) or (ins)) which is printed in front of the bash prompt? This mode string is activated by set show-mode-in-prompt on in .inputrc.

I want to determine the length of this string from within $PROMPT_COMMAND.

I'm trying to do some cursor movement with tput inside the prompt to print some info on the terminal's right hand side (so that it can be overwritten if need be), then resume printing the prompt on the left, but I need to take into account the length of the mode string.

Is $PROMPT_COMMAND called again and the prompt reprinted if changing mode (e.g) emacs-mode-string to vi-ins-mode-string as the prefix?

Tom Hale
  • 30,455

1 Answers1

0

Not really an answer to the question regarding mode string length, but a workaround:

I ended up using ANSI CSI codes to save and restore the position of the cursor. (Thanks @tripleee for the pointer).

I was still unable to find the length of the mode string, even when tying to get the cursor position using PS1=$(getColumn) where getColumn was various things I tried based on:

My work-around using ANSI CSI codes can be found as in answer to "Right align part of prompt".

I'm pretty pleased with the work-around as I manged to do it without a single sub-process, and make it shellcheck-clean.

Tom Hale
  • 30,455