-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Ji4n1ng/develop
feat(Core): Support Alacritty
- Loading branch information
Showing
8 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// AlacrittyApp.swift | ||
// OpenInTerminalCore | ||
// | ||
// Created by Jianing Wang on 2019/4/25. | ||
// Copyright © 2019 Jianing Wang. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
final class AlacrittyApp : Openable { | ||
|
||
func open(_ path: String, _ newOption: NewOptionType) throws { | ||
|
||
guard let url = URL(string: path) else { | ||
throw OITError.wrongUrl | ||
} | ||
|
||
let source = """ | ||
do shell script "open -na alacritty --args --working-directory \(url.path.alacrittyEscaped)" | ||
""" | ||
|
||
let script = NSAppleScript(source: source)! | ||
|
||
var error: NSDictionary? | ||
|
||
script.executeAndReturnError(&error) | ||
|
||
if error != nil { | ||
log(error, .error) | ||
throw OITError.cannotAccessHyper | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
fileprivate extension String { | ||
|
||
// FIXME: if path contains "\" or """, application will crash. | ||
// Special symbols have been tested, except for backslashes and double quotes. | ||
var alacrittyEscaped: String { | ||
|
||
var result = "" | ||
let set: [Character] = [" ", "(", ")", "&", "|", ";", | ||
"\"", "'", "<", ">", "`"] | ||
|
||
for char in self { | ||
if set.contains(char) { | ||
result += "\\\\" | ||
} | ||
result.append(char) | ||
} | ||
|
||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters