Comments (4)
There has been some discussion on bug-readline, about doing this for readine itself, where the conclusion was that this is not so simple. rlwrap
s hotkey is very similar, however: CTRL+R
could be bound to rlwrap-hotkey
, where the hotkey handler could do something along the lines of your example.
Problem: in bash
, the hotkey handler is a shell function that can "see" everything because it runs in the same process as the shell itself. A filter is a separate, lonely process that can not look into rlwrap
nor the rlwrapped command. cloak_and_dagger()
can pry some information from the latter, but rlwrap
itself is a black box.
A possible solution would be to send as much information as possible in a HOTKEY
message: not only the current input line, but e.g. also the current history. The handler would have to be something like this
$filter -> hotkey_handler(sub {
my($key, $input_line, $cursor_position, $history, $history_position, ....) = @_
if ($key == control('R')) {
my ($new_line, $new_cursorpos) = use_peco_to_get_a_line($history);
return("", $new_line, $new_cursorpos, $history, $history_position,....);
}
}
This would subsume the current rlwrap-edit-history
function as well, and thus get rid of some code (at the expense of a slightly more complex hotkey handler)
If sending the complete history for every hotkey keystroke is a bit too much, I could also implement a rlwrap-hotkey-without-history
function, for those hotkeys that don't need the complete history
from rlwrap.
I worked this out in branch hash_history, and this looks quite promising. History edit is now done in a few lines of perl
(or python
), and the existing --multi-line
support could also easily be subsumed under rlwrap-hotkey
. I cannot easily try peco
on my linux machine, but I don't see why this wouldn't be straightforward as well.
One little twist should/will be added to the hotkey handler: if the returned input line ends with a newline, immediately accept the result, otherwise keep editing. So, if (and only if) we e.g. put two empty lines before a history line (or e.g. end a multi-line edit with a '!') accept the result
from rlwrap.
Thanks a lot for the great work! That is what I really want! I added peco
handler to the handle_hotkeys
script and it works fine! Please review my pull request which has a peco
handler and a minor bug fix.
from rlwrap.
All merged and done. Closing.
from rlwrap.
Related Issues (20)
- Can rlwrap catch SIGINT? HOT 2
- Is multi word input possible HOT 15
- option rlwrap displays prompt at cursor position HOT 1
- is it possible to exit rlwrap with escape HOT 4
- Press Enter twice to send a command with weird suffix HOT 1
- Python filter can't be loaded HOT 4
- build failed: possibly undefined macro: AM_INIT_AUTOMAKE HOT 1
- brew install for rlwrap fails on a mac (m1 arm) HOT 1
- rlwrap rewrites the input line right-shifted HOT 12
- rlwrap segfaults on test program HOT 1
- Right-shifted input (or double prompt) after accepting a line in bracketed-paste-mode with readline-8.2 HOT 19
- The rlwrap program occasionally fails on several Solaris machines creating a fault alert HOT 4
- programs (like php -a) that put even a dumb terminal in bracketed-paste mode confuse rlwrap HOT 1
- rlwrap kills forked children HOT 2
- [feature] shell completion HOT 3
- Minor issue about english HOT 1
- rlwrap -a bc duplicates the line to the right HOT 1
- configure cannot find readline in non-root install HOT 6
- -f . should fail silently if there is no history (yet) HOT 2
- rlwrap modifies a line after entering HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rlwrap.