mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-09 23:17:55 +02:00
Quote initial commands to make it possible to easily use hishtory to find matching entries for already typed commands that contain flags (#251)
* Quote initial commands to make it possible to easily use hishtory to find matching entries for already typed commands that contain flags * Add test for quoting dashes * Fix test failures * More test fixes * Update goldens * Update goldens * Update goldens * Fix race condition * Fix test harness bug by swapping to splitn * Update goldens * Update golden * Update test
This commit is contained in:
@ -965,7 +965,9 @@ func splitEscaped(query string, separator rune, maxSplit int) []string {
|
||||
isInSingleQuotedString := false
|
||||
for i := 0; i < len(runeQuery); i++ {
|
||||
if (maxSplit < 0 || splits < maxSplit) && runeQuery[i] == separator && !isInSingleQuotedString && !isInDoubleQuotedString {
|
||||
tokens = append(tokens, string(token))
|
||||
if string(token) != "" {
|
||||
tokens = append(tokens, string(token))
|
||||
}
|
||||
token = token[:0]
|
||||
splits++
|
||||
} else if runeQuery[i] == '\\' && i+1 < len(runeQuery) {
|
||||
@ -982,8 +984,13 @@ func splitEscaped(query string, separator rune, maxSplit int) []string {
|
||||
} else if runeQuery[i] == '\'' && !isInDoubleQuotedString && !heuristicIgnoreUnclosedQuote(isInSingleQuotedString, '\'', runeQuery, i) {
|
||||
isInSingleQuotedString = !isInSingleQuotedString
|
||||
} else {
|
||||
if (isInSingleQuotedString || isInDoubleQuotedString) && separator == ' ' && runeQuery[i] == ':' {
|
||||
token = append(token, '\\')
|
||||
if (isInSingleQuotedString || isInDoubleQuotedString) && separator == ' ' {
|
||||
if runeQuery[i] == ':' {
|
||||
token = append(token, '\\')
|
||||
}
|
||||
if runeQuery[i] == '-' && len(token) == 0 {
|
||||
token = append(token, '\\')
|
||||
}
|
||||
}
|
||||
token = append(token, runeQuery[i])
|
||||
}
|
||||
|
Reference in New Issue
Block a user