How to correctly link patched GNU readline library to all existing programs?

本小妞迷上赌 提交于 2019-12-09 23:55:45

问题


My original issue was that I wanted a way to distinguish between whether I am in vi-command mode or vi-insert mode while using bash in vi-mode. I understand that as of GNU readline 7.0 there is a way to set an indicator in the command prompt; however, what I want is rather to change the shape of the cursor (i.e. a vertical line while in insert mode and a solid block while in command mode).


NOTE: I already tried placing the following in my .inputrc, which did the trick, but it caused some issues while moving back to the beginning of the line while in command mode, so I concluded that is was not a good alternative.

set show-mode-in-prompt on
set vi-cmd-mode-string "\e[2 q"
set vi-ins-mode-string "\e[6 q"


I came across an article written by someone who was having the same issue, and eventually decided to patch the GNU readline library himself, linked here below:

http://blog.mkoskar.com/2010/10/gnu-readline-vi-mode-visualization.html http://blog.mkoskar.com/2010/11/gnu-readline-vi-mode-visualization-2.html


So far I have been able to successfully apply the patch and compile / install the library (locally... I'd prefer to keep the unpatched version installed in case I ever wanted to switch back), but bash seems to still be using the original.

Here are the important details:

1) The patched library files (static and dynamic) are located on my computer at $HOME/.local/lib/.
2) The original library files (dynamic only) I have determined are located at /lib/x86_64-linux-gnu/.
3) My LD_LIBRARY_PATH environment variable is set to $HOME/.local/lib: within my .bashrc.


Even with the patched version installed and my LD_LIBRARY_PATH variable set correctly, Bash still seems to not use my patched GNU readline library. I am wondering if there is something I am doing wrong?

I hope that the issue is not that Bash comes with the readline library already statically linked, requiring me, I suppose, to reinstall Bash (as well as any other programs that use this library, such as iPython), manually linking in the patched version of readline.


SOLUTION

While not the solution to the question listed in the title, this is the solution to the original issue I was having. After looking through Readline's man pages, I came across the following descriptions for vi-cmd-mode-string and vi-ins-mode-string:

vi-cmd-mode-string ((cmd))
       This  string  is  displayed immediately before the last line of the primary prompt when vi editing mode is active and in command mode.  The value is expanded like a key binding, so the
       standard set of meta- and control prefixes and backslash escape sequences is available.  Use the \1 and \2 escapes to begin and end sequences of non-printing characters, which  can  be
       used to embed a terminal control sequence into the mode string.
vi-ins-mode-string ((ins))
       This  string is displayed immediately before the last line of the primary prompt when vi editing mode is active and in insertion mode.  The value is expanded like a key binding, so the
       standard set of meta- and control prefixes and backslash escape sequences is available.  Use the \1 and \2 escapes to begin and end sequences of non-printing characters, which  can  be
       used to embed a terminal control sequence into the mode string.

The part about the \1 and \2 escapes is the important stuff...


So basically, placing the following in my .inputrc allowed me to set the cursor shape depending on the current vi mode:

set show-mode-in-prompt on
set vi-cmd-mode-string "\1\e[2 q\2"
set vi-ins-mode-string "\1\e[6 q\2"

来源:https://stackoverflow.com/questions/45136948/how-to-correctly-link-patched-gnu-readline-library-to-all-existing-programs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!