* GUI utility for escaping cmdline arguments
This commit is contained in:
parent
27e7ddc4a7
commit
32fe29653e
|
@ -1,7 +1,26 @@
|
||||||
net.sourceforge.filebot.cli.CLILogging.CLILogger.setLevel(java.util.logging.Level.OFF)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def escapeShell(String arg) {
|
||||||
|
return arg.replaceAll(/["$`<>^\\"']/, /\\$0/)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (java.awt.GraphicsEnvironment.headless) {
|
||||||
|
// CLI mode
|
||||||
console.printf('Enter: ')
|
console.printf('Enter: ')
|
||||||
def s = console.readLine()
|
def s = console.readLine()
|
||||||
|
console.println('\n' + escapeShell(s) + '\n')
|
||||||
// ‘$’, ‘`’, or ‘\’
|
System.exit(0)
|
||||||
console.printf('%n"' + s.replaceAll('["$`\\\\]', {'\\'+it}) + '"%n')
|
} else {
|
||||||
|
// GUI mode
|
||||||
|
new groovy.swing.SwingBuilder().edt {
|
||||||
|
frame(title: 'Escape', size: [350, 230], show: true, defaultCloseOperation: javax.swing.JFrame.EXIT_ON_CLOSE) {
|
||||||
|
gridLayout(cols: 1, rows: 2)
|
||||||
|
textArea id: 'value', lineWrap: true, font: new java.awt.Font('Monospaced', 0, 16)
|
||||||
|
textArea id: 'escape', lineWrap: true, text: bind(source:value, sourceProperty:'text', converter: { escapeShell(it) }), font: new java.awt.Font('Monospaced', 0, 16)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.in.read() // wait for GUI to close
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue