From 2d22e8c0414f3e28b538a7369fa5fab7a163a731 Mon Sep 17 00:00:00 2001 From: Marco Paganini Date: Tue, 27 Aug 2024 20:01:40 -0700 Subject: [PATCH] Make bind_snip_add call "snip add" (no paste in prompt). --- snip | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/snip b/snip index 7b2566e..71ca284 100755 --- a/snip +++ b/snip @@ -304,6 +304,8 @@ function add() { die "${PROGRAM} ERROR: command cannot contain newlines\nCommand entered:\n${cmd}" fi + echo "Adding Snippet: ${cmd}" + # Read description rejecting invalid chars and blank lines. while :; do read -re -p "Description (one line): " desc @@ -382,12 +384,16 @@ function find() { # snip_bind_add - Bindings to add the current command-line to the database. function snip_bind_add() { if [[ -n "${READLINE_LINE}" ]]; then - tmp="$(mktemp)" - old_readline_line="${READLINE_LINE}" - echo "${READLINE_LINE}" >"${tmp}" - # One space before the program prevents it from being added to the history. - READLINE_LINE=" ${SNIP_PROGRAM:-snip} add -f ${tmp} --delete ### Command: ${old_readline_line}" + # Empirically discovered that bind apparently turns off icrnl, icanon, and + # echo on the TTY. We need to turn it back on so the user can enter the + # description. We also need to turn if back OFF at the end, or strangeness + # will result (like not being able to edit the line upon return to the + # prompt, etc). + stty icrnl icanon echo + ${SNIP_PROGRAM:-snip} add "${READLINE_LINE}" + READLINE_LINE="" READLINE_POINT="${#READLINE_LINE}" + stty -icrnl -icanon -echo fi } @@ -399,7 +405,6 @@ function snip_bind_find() { if [[ -n "${cmd}" ]]; then READLINE_LINE="${cmd}" READLINE_POINT="${#READLINE_LINE}" - READLINE_MARK="${READLINE_POINT}" fi }