Skip to content

Instantly share code, notes, and snippets.

View DanSM-5's full-sized avatar

Eduardo D Sanchez DanSM-5

View GitHub Profile
@DanSM-5
DanSM-5 / edit-prompt-in-editor.sh
Created May 11, 2024 20:37
Edit prompt in editor (C-x C-e) for bash, zsh and powershell
# Bash
# Credits: https://unix.stackexchange.com/a/684760
# Difference with built-in one is that it won't run the
# command when closing the editor
__edit_command_no_execute () {
local editor="${EDITOR:-vim}"
local tmpf="$(mktemp)"
printf '%s\n' "$READLINE_LINE" >| "$tmpf"
"$editor" "$tmpf"
READLINE_LINE="$(cat "$tmpf")"