ghostty/macos/Sources/Ghostty/Ghostty.Shell.swift
2024-08-21 21:53:09 +02:00

20 lines
542 B
Swift

extension Ghostty {
struct Shell {
// Characters to escape in the shell.
static let escapeCharacters = "\\ ()[]{}<>\"'`!#$&;|*?\t"
/// Escape shell-sensitive characters in string.
static func escape(_ str: String) -> String {
var result = str
for char in escapeCharacters {
result = result.replacingOccurrences(
of: String(char),
with: "\\\(char)"
)
}
return result
}
}
}