github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/shell/history/colon.go (about) 1 package history 2 3 func noColon(line string) string { 4 var escape, qSingle, qDouble, funcStart bool 5 6 for i := 0; i < len(line); i++ { 7 switch line[i] { 8 case '#': 9 return line 10 case '\\': 11 switch { 12 case escape: 13 escape = false 14 case qSingle: 15 // do nothing 16 default: 17 escape = true 18 } 19 case '\'': 20 switch { 21 case qDouble, escape: 22 escape = false 23 default: 24 qSingle = !qSingle 25 } 26 case '"': 27 switch { 28 case qSingle, escape: 29 escape = false 30 default: 31 qDouble = !qDouble 32 } 33 case '{': 34 if !escape && !qSingle && !qDouble { 35 return line 36 } 37 case '\r', '\n', '\t', ' ': 38 if !escape && !qSingle && !qDouble { 39 return line 40 } 41 case ':': 42 if !escape && !qSingle && !qDouble { 43 switch { 44 case !funcStart: 45 line = line[i+1:] 46 funcStart = true 47 continue 48 49 // colon mid command - must split 50 case i < len(line)-1 && line[i+1] != ' ': 51 return line[:i] + " " + line[i+1:] 52 53 default: 54 return line[:i] + line[i+1:] 55 } 56 } 57 default: 58 funcStart = true 59 } 60 } 61 62 return line 63 }