Repository: evan-liu/karabiner.ts (ts)

Issue:
toApp() parameter need to have double quote when app name has two words
e.g "System Settings”

Pull request description:
🐛 Fix #21 toApp() needs double quote when there is space in app name

Patch:
diff --git a/src/config/manipulator.ts b/src/config/manipulator.ts
index a27c5bf..42ac6f1 100644
--- a/src/config/manipulator.ts
+++ b/src/config/manipulator.ts
@@ -55,7 +55,8 @@ export class ManipulatorBuilder {
 
   /** Map to `$ open -a {app}.app` */
   toApp(app: string) {
-    return this.to$(`open -a ${app.endsWith('.app') ? app : `${app}.app`}`)
+    const matched = app.match(/^"?(.*?)(.app)?"?$/)
+    return this.to$(`open -a "${matched?.[1] || app}".app`)
   }
 
   /** Map to paste {text} via clipboard */


Test patch:
diff --git a/src/config/manipulator.test.ts b/src/config/manipulator.test.ts
index 590915a..32a659b 100644
--- a/src/config/manipulator.test.ts
+++ b/src/config/manipulator.test.ts
@@ -40,11 +40,27 @@ describe('ManipulatorBuilder', () => {
       .toPaste('test')
       .build().to as Array<{ shell_command: string }>
     expect(to[0]).toEqual({ shell_command: 'cd' })
-    expect(to[1]).toEqual({ shell_command: 'open -a Finder.app' })
-    expect(to[2]).toEqual({ shell_command: 'open -a Xcode.app' })
+    expect(to[1]).toEqual({ shell_command: 'open -a "Finder".app' })
+    expect(to[2]).toEqual({ shell_command: 'open -a "Xcode".app' })
     expect(to[3].shell_command).toMatch('"test"')
   })
 
+  test('toApp() with space in name', () => {
+    expect(
+      new ManipulatorBuilder(from)
+        .toApp('System Settings')
+        .toApp('System Settings.app')
+        .toApp('"System Settings"')
+        .toApp('"System Settings.app"')
+        .build().to as Array<{ shell_command: string }>,
+    ).toEqual([
+      { shell_command: 'open -a "System Settings".app' },
+      { shell_command: 'open -a "System Settings".app' },
+      { shell_command: 'open -a "System Settings".app' },
+      { shell_command: 'open -a "System Settings".app' },
+    ])
+  })
+
   test('toVar()', () => {
     expect(
       new ManipulatorBuilder(from).toVar('a', 1).toVar('b', true).build().to,