How can you get the current terminal line (the one that is still editable by the user)?
4
votes
1
answer
1901
views
I need a way to use the current line which the users typed into as variable for a shell function.
my current code, which can be called by ctrl+r
zle -N search
bindkey "^R" search
search () {
read str;
fc -ln -30 | grep $(printf "%q\n" "$str");
}
or simply, to call it as a function
search () {
fc -ln -30 | grep $(printf "%q\n" "$1");
}
updated: target pseudo code, to call as a function called by ctrl+r that needs no further input prompt
zle -N search
bindkey "^R" search
search ()
echo ""; #for better formatting because ctrl+R is not enter so the BUFFER(current line) gets corrupted and looks messy and the current input is not correctly shown
fc -ln -30 | grep $(printf "%q\n" "$BUFFER"); #edited to be the solution where $BUFFER is the current terminal line
}
Asked by HopefullyHelpful
(161 rep)
Aug 26, 2014, 02:56 PM
Last activity: Sep 26, 2020, 04:49 PM
Last activity: Sep 26, 2020, 04:49 PM