fix: store and execute multiline commands in pos bank
gates / consistency-and-conventions (push) Successful in 20s

bank.env is line-oriented (name|description|command) so commands with
real newlines spanned records: bank_load truncated the command to its
first line and the remaining script lines became bogus entries. The
bank_get+cut -f3 retrieval path also truncated at embedded tabs.

- lib/bank-lib.sh: v2 format escapes backslash->\\ and newline->\\n
  in the command field, writes # BANK_VERSION: 2; bank_load decodes
  with printf %b only for v2 files, so existing v1 files load raw
  (backward compatible, verified against the real ts-google entry).
- bin/pos-bank: cmd_show/cmd_run/cmd_edit now read fields from the
  BANK_* arrays via bank_find instead of bank_get+cut.
- tests/t-bank.sh: +13 checks (71 total) - multiline round-trip exact
  bytes, literal backslash-n, v1 raw-backslash compat, v1+re-save
  byte-identical, CLI show/run full script.
This commit is contained in:
Your Name
2026-09-12 08:25:40 -04:00
parent e23d57e551
commit 11b4a679a8
5 changed files with 132 additions and 22 deletions
+12 -15
View File
@@ -114,12 +114,11 @@ cmd_show() {
[ -n "${1:-}" ] || err "Usage: pos bank show <name>"
local name="$1"
bank_load
local entry
entry="$(bank_get "$name")" || err "Command not found: $name"
bank_find "$name" >/dev/null 2>&1 || err "Command not found: $name"
local cmd_name cmd_desc cmd_cmd
cmd_name="$(printf '%s' "$entry" | cut -f1)"
cmd_desc="$(printf '%s' "$entry" | cut -f2)"
cmd_cmd="$(printf '%s' "$entry" | cut -f3)"
cmd_name="${BANK_NAMES[$BANK_IDX]}"
cmd_desc="${BANK_DESCS[$BANK_IDX]}"
cmd_cmd="${BANK_CMDS[$BANK_IDX]}"
echo
echo "Name: $cmd_name"
echo
@@ -162,12 +161,11 @@ cmd_run() {
done
fi
bank_load
local entry
entry="$(bank_get "$name")" || err "Command not found: $name"
bank_find "$name" >/dev/null 2>&1 || err "Command not found: $name"
local cmd_name cmd_desc cmd_cmd
cmd_name="$(printf '%s' "$entry" | cut -f1)"
cmd_desc="$(printf '%s' "$entry" | cut -f2)"
cmd_cmd="$(printf '%s' "$entry" | cut -f3)"
cmd_name="${BANK_NAMES[$BANK_IDX]}"
cmd_desc="${BANK_DESCS[$BANK_IDX]}"
cmd_cmd="${BANK_CMDS[$BANK_IDX]}"
# Detect parameters
local params_str
params_str="$(_extract_params "$cmd_cmd")"
@@ -218,12 +216,11 @@ cmd_edit() {
name="$(_pick_command)" || return 0
fi
bank_load
local entry
entry="$(bank_get "$name")" || err "Command not found: $name"
bank_find "$name" >/dev/null 2>&1 || err "Command not found: $name"
local old_name old_desc old_cmd
old_name="$(printf '%s' "$entry" | cut -f1)"
old_desc="$(printf '%s' "$entry" | cut -f2)"
old_cmd="$(printf '%s' "$entry" | cut -f3)"
old_name="${BANK_NAMES[$BANK_IDX]}"
old_desc="${BANK_DESCS[$BANK_IDX]}"
old_cmd="${BANK_CMDS[$BANK_IDX]}"
echo
log "Editing: $old_name"
echo