diff --git a/cmd/sanitize/main.go b/cmd/sanitize/main.go index a7415b1..e5630de 100644 --- a/cmd/sanitize/main.go +++ b/cmd/sanitize/main.go @@ -173,11 +173,42 @@ func (s *sanitizer) sanitizeRecord(record *records.Record) error { log.Fatal("Cmd:", record.CmdLine, "; sanitization error:", err) } + if len(record.RecallActionsRaw) > 0 { + record.RecallActionsRaw, err = s.sanitizeRecallActions(record.RecallActionsRaw) + if err != nil { + log.Fatal("RecallActionsRaw:", record.RecallActionsRaw, "; sanitization error:", err) + } + } // add a flag to signify that the record has been sanitized record.Sanitized = true return nil } +// sanitizes the recall actions by replacing the recall prefix with it's length +func (s *sanitizer) sanitizeRecallActions(str string) (string, error) { + sanStr := "" + for x, actionStr := range strings.Split(str, ";") { + if x == 0 { + continue + } + if len(actionStr) == 0 { + return str, errors.New("Action can't be empty; idx=" + strconv.Itoa(x)) + } + fields := strings.Split(actionStr, ":") + if len(fields) != 2 { + return str, errors.New("Action should have exactly one ':' - encountered:" + actionStr) + } + action := fields[0] + if action != "arrow_up" && action != "arrow_down" { + return str, errors.New("Action (part 1) should be either 'arrow_up' or 'arrow_down' - encountered:" + action) + } + prefix := fields[1] + sanPrefix := strconv.Itoa(len(prefix)) + sanStr += ";" + action + ":" + sanPrefix + } + return sanStr, nil +} + func (s *sanitizer) sanitizeCmdLine(cmdLine string) (string, error) { const optionEndingChars = "\"$'\\#[]!><|;{}()*,?~&=`:@^/+%." // all bash control characters, '=', ... const optionAllowedChars = "-_" // characters commonly found inside of options diff --git a/scripts/reshctl.sh b/scripts/reshctl.sh index b82cccb..a9c9376 100644 --- a/scripts/reshctl.sh +++ b/scripts/reshctl.sh @@ -46,7 +46,7 @@ __resh_unbind_arrows() { echo "Warn: Couldn't revert arrow DOWN binding because 'revert command' is empty." else eval "$__RESH_bindfunc_revert_arrow_down_bind" - [ -z "${__RESH_bindfunc_revert_arrow_up_bind_vim+x}" ] || eval "$__RESH_bindfunc_revert_arrow_up_bind_vim" + [ -z "${__RESH_bindfunc_revert_arrow_down_bind_vim+x}" ] || eval "$__RESH_bindfunc_revert_arrow_down_bind_vim" echo "RESH arrow down binding successfully disabled ✓" __RESH_arrow_keys_bind_enabled=0 fi