aboutsummaryrefslogtreecommitdiff
path: root/src/utils.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.nim')
-rw-r--r--src/utils.nim14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils.nim b/src/utils.nim
index 1d7c6bd..8316110 100644
--- a/src/utils.nim
+++ b/src/utils.nim
@@ -179,6 +179,20 @@ proc removeDirQuiet*(s: string) =
except:
discard
+const bashSpecialCharacters = " \t\"'`()[]{}#&|;!\\*~<>?"
+
+proc bashEscape*(s: string): string =
+ result = ""
+ for c in s:
+ if c in bashSpecialCharacters:
+ result &= "\\" & c
+ elif c == "\n"[0]:
+ result &= "$'\\n'"
+ elif c.cuint < 0x20.cuint or c.cuint > 0x80.cuint:
+ result &= "$'\\0x" & c.toHex & "'"
+ else:
+ result &= c
+
proc dgettext(domain: cstring, s: cstring): cstring
{.cdecl, importc: "dgettext".}