Replies: 2 comments
-
since you didn't reply ill assume it is and explain. When the a function is bound (eg bind -x ) to a key and sourced what happens is the shell (the ones that use readline) takes a snapshot of whats written in the consol and saves it to the variable $READLINE_LINE and saves the cursor position (n) as $READLINE_POINT and when you exit out the screen is sent a clrs (clear screen) and it then replaces your command line with $READLINE_LINE and places your cursor at $READLINE_POINT so your function should first save the variables as something esle __main__() {
origPoint="$READLINE_POINT"
orgLine="$READLINE_LINE"
choice="$(some command | fzf-command --flags --preview='whatever {}')"
READLINE_LINE="$READLINE_LINE $(tr '\n' ' ' <<<"${_choice#*$'\t'}")"
if [[ -n "$READLINE_LINE" ]]; then
print '%s '"$READLINE_LINE" | \
tr \\n \\s;
READLINE_POINT=0x7fffffff; else
READLINE_POINT=0x7fffffff
fi
unset origPoint
unset origLine
unset nwLine So you just need a command that populates fzf with a list of commands, I use: coms () {
case "$PATH" in
(*[!:]:) PATH="$PATH:" ;;
esac
set -f; IFS=:
for dir in $PATH; do
set +f
[ -z "$dir" ] && dir="."
for file in "$dir"/*; do
if [ -x "$file" ] && ! [ -d "$file" ]; then
printf '%s = %s\n' "${file##*/}" "$file"
fi
done
done
} from here you can either do coms | awk '{print $1}'
#or
coms | fzf --nth 1
|
Beta Was this translation helpful? Give feedback.
-
I would like to insert a command from history from any point in the line editor. Essentially, have another binding that does the exact same as Ctrl-R (insert command from history) except it is not narrowed down by what is currently in the line editor as CTRL-R does.
CTRL-R also does some nice things like not printing duplicate commands, empty lines, etc. that should preferably be replicated.
A use case would be something like:
<some command> | <insert any command available in CTRL-R that is not narrowed by "<some command> |", i.e. as if you pressed CTRL-R with the line editor being empty>
. Is this possible?Beta Was this translation helpful? Give feedback.
All reactions