Created
November 26, 2023 09:17
-
-
Save tspng/9cb4a4c9f55f8dab2433c13a27d8d1c8 to your computer and use it in GitHub Desktop.
Revisions
-
pmorelli92 revised this gist
Jun 4, 2019 . 1 changed file with 17 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ #!/usr/bin/xcrun swift // // Copyright © 2016 Leon Breedt // Ported to Swift 5 by Pablo Morelli 2019 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -122,44 +123,44 @@ func convertToTerminalColors(itermFile: String, terminalFile: String) { /// Converts an iTerm color scheme dictionary into a Terminal.app color scheme dictionary. func convert(iTermColorScheme: NSDictionary, toTerminalSchemeWithName name: String) -> NSDictionary { var terminalColorScheme: [String: Any] = [ "name" : name, "type" : "Window Settings", "ProfileCurrentVersion" : 2.04, "columnCount": 90, "rowCount": 50 ] // SF Mono is pretty sweet. if let font = archivedFontWithName(name: "SF Mono Regular", size: 13) { terminalColorScheme["Font"] = font } for (rawKey, rawValue) in iTermColorScheme { guard let name = rawKey as? String else { continue } guard let itermDict = rawValue as? NSDictionary else { continue } guard let itermKey = iTermColors(rawValue: name) else { continue } guard let terminalKey = iTermColor2TerminalColor[itermKey] else { continue } let (r, g, b) = ( (itermDict[iTermColorComponent.red] as? CGFloat) ?? CGFloat(0), (itermDict[iTermColorComponent.green] as? CGFloat) ?? CGFloat(0), (itermDict[iTermColorComponent.blue] as? CGFloat) ?? CGFloat(0) ) let color = NSColor(deviceRed: r, green: g, blue: b, alpha: 1) let data = try! NSKeyedArchiver.archivedData(withRootObject: color, requiringSecureCoding: true) terminalColorScheme[terminalKey.rawValue] = data } return terminalColorScheme as NSDictionary } /// Creates an `NSData` representation of an `NSFont`. func archivedFontWithName(name: String, size: CGFloat) -> Data? { if let font = NSFont(name: name, size: size) { return try! NSKeyedArchiver.archivedData(withRootObject: font, requiringSecureCoding: true) } return nil } @@ -172,12 +173,12 @@ extension String { let path = ns.standardizingPath var directory = ns.deletingLastPathComponent if directory.utf8.count == 0 { directory = FileManager.default.currentDirectoryPath } return directory.ns.appendingPathComponent(path) } } /// Convenience property for accessing this string as an `NSString`. var ns: NSString { return self as NSString @@ -186,7 +187,7 @@ extension String { } // Entry point. let args = CommandLine.arguments.dropFirst() if args.count > 0 { for itermFile in args { let path = itermFile.fullPath @@ -197,4 +198,4 @@ if args.count > 0 { } } else { print("usage: iTermColorsToTerminalColors FILE.itermcolors [...]") } -
leonbreedt revised this gist
Jun 17, 2016 . 1 changed file with 14 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,19 @@ #!/usr/bin/xcrun swift // // Copyright © 2016 Leon Breedt // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. import Cocoa -
leonbreedt revised this gist
Jun 17, 2016 . No changes.There are no files selected for viewing
-
leonbreedt revised this gist
Jun 17, 2016 . 1 changed file with 157 additions and 145 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,175 +1,187 @@ #!/usr/bin/xcrun swift // Swift 3.0 script for converting an iTerm color scheme to a Swift color scheme. import Cocoa /// Enumerates the colors in an iTerm color scheme. enum iTermColors: String { case ansi0 = "Ansi 0 Color" case ansi1 = "Ansi 1 Color" case ansi2 = "Ansi 2 Color" case ansi3 = "Ansi 3 Color" case ansi4 = "Ansi 4 Color" case ansi5 = "Ansi 5 Color" case ansi6 = "Ansi 6 Color" case ansi7 = "Ansi 7 Color" case ansi8 = "Ansi 8 Color" case ansi9 = "Ansi 9 Color" case ansi10 = "Ansi 10 Color" case ansi11 = "Ansi 11 Color" case ansi12 = "Ansi 12 Color" case ansi13 = "Ansi 13 Color" case ansi14 = "Ansi 14 Color" case ansi15 = "Ansi 15 Color" case cursorText = "Cursor Text Color" case selectedText = "Selected Text Color" case foreground = "Foreground Color" case background = "Background Color" case bold = "Bold Color" case selection = "Selection Color" case cursor = "Cursor Color" } /// Enumerates the colors in a Terminal.app color scheme. enum TerminalColors: String { case ansiBlack = "ANSIBlackColor" case ansiRed = "ANSIRedColor" case ansiGreen = "ANSIGreenColor" case ansiYellow = "ANSIYellowColor" case ansiBlue = "ANSIBlueColor" case ansiMagenta = "ANSIMagentaColor" case ansiCyan = "ANSICyanColor" case ansiWhite = "ANSIWhiteColor" case ansiBrightBlack = "ANSIBrightBlackColor" case ansiBrightRed = "ANSIBrightRedColor" case ansiBrightGreen = "ANSIBrightGreenColor" case ansiBrightYellow = "ANSIBrightYellowColor" case ansiBrightBlue = "ANSIBrightBlueColor" case ansiBrightMagenta = "ANSIBrightMagentaColor" case ansiBrightCyan = "ANSIBrightCyanColor" case ansiBrightWhite = "ANSIBrightWhiteColor" case background = "BackgroundColor" case text = "TextColor" case boldText = "BoldTextColor" case selection = "SelectionColor" case cursor = "CursorColor" } // Mapping of iTerm colors onto corresponding Terminal.app colors. let iTermColor2TerminalColor = [ iTermColors.ansi0: TerminalColors.ansiBlack, iTermColors.ansi1: TerminalColors.ansiRed, iTermColors.ansi2: TerminalColors.ansiGreen, iTermColors.ansi3: TerminalColors.ansiYellow, iTermColors.ansi4: TerminalColors.ansiBlue, iTermColors.ansi5: TerminalColors.ansiMagenta, iTermColors.ansi6: TerminalColors.ansiCyan, iTermColors.ansi7: TerminalColors.ansiWhite, iTermColors.ansi8: TerminalColors.ansiBrightBlack, iTermColors.ansi9: TerminalColors.ansiBrightRed, iTermColors.ansi10: TerminalColors.ansiBrightGreen, iTermColors.ansi11: TerminalColors.ansiBrightYellow, iTermColors.ansi12: TerminalColors.ansiBrightBlue, iTermColors.ansi13: TerminalColors.ansiBrightMagenta, iTermColors.ansi14: TerminalColors.ansiBrightCyan, iTermColors.ansi15: TerminalColors.ansiBrightWhite, iTermColors.background: TerminalColors.background, iTermColors.foreground: TerminalColors.text, iTermColors.selection: TerminalColors.selection, iTermColors.bold: TerminalColors.boldText, iTermColors.cursor: TerminalColors.cursor, ] /// Enumerates the names of iTerm color components in the scheme dictionary. struct iTermColorComponent { static let red = "Red Component" static let green = "Green Component" static let blue = "Blue Component" } /// Converts an iTerm color scheme file (.itermcolors), into a Terminal.app color scheme /// file (.terminal). func convertToTerminalColors(itermFile: String, terminalFile: String) { if let itermScheme = NSDictionary(contentsOfFile: itermFile) { print("converting \(itermFile) -> \(terminalFile)") let name = terminalFile.ns.lastPathComponent.ns.deletingPathExtension let terminalScheme = convert(iTermColorScheme: itermScheme, toTerminalSchemeWithName: name) terminalScheme.write(toFile: terminalFile, atomically: true) } else { print("unable to load \(itermFile)") } } /// Converts an iTerm color scheme dictionary into a Terminal.app color scheme dictionary. func convert(iTermColorScheme: NSDictionary, toTerminalSchemeWithName name: String) -> NSDictionary { var terminalColorScheme: [String: AnyObject] = [ "name" : name, "type" : "Window Settings", "ProfileCurrentVersion" : 2.04, "columnCount": 90, "rowCount": 50 ] // SF Mono is pretty sweet. if let font = archivedFontWithName(name: "SF Mono Regular", size: 13) { terminalColorScheme["Font"] = font } for (rawKey, rawValue) in iTermColorScheme { guard let name = rawKey as? String else { continue } guard let itermDict = rawValue as? NSDictionary else { continue } guard let itermKey = iTermColors(rawValue: name) else { continue } guard let terminalKey = iTermColor2TerminalColor[itermKey] else { continue } let (r, g, b) = ( (itermDict[iTermColorComponent.red] as? CGFloat) ?? CGFloat(0), (itermDict[iTermColorComponent.green] as? CGFloat) ?? CGFloat(0), (itermDict[iTermColorComponent.blue] as? CGFloat) ?? CGFloat(0) ) let color = NSColor(deviceRed: r, green: g, blue: b, alpha: 1) let data = NSKeyedArchiver.archivedData(withRootObject: color) terminalColorScheme[terminalKey.rawValue] = data } return terminalColorScheme } /// Creates an `NSData` representation of an `NSFont`. func archivedFontWithName(name: String, size: CGFloat) -> NSData? { if let font = NSFont(name: name, size: size) { return NSKeyedArchiver.archivedData(withRootObject: font) } return nil } extension String { /// Gets the canonical version of a path. var fullPath: String { get { let path = ns.standardizingPath var directory = ns.deletingLastPathComponent if directory.utf8.count == 0 { directory = FileManager.default().currentDirectoryPath } return directory.ns.appendingPathComponent(path) } } /// Convenience property for accessing this string as an `NSString`. var ns: NSString { return self as NSString } } // Entry point. let args = Process.arguments.dropFirst() if args.count > 0 { for itermFile in args { let path = itermFile.fullPath let folder = path.ns.deletingLastPathComponent let schemeName = path.ns.lastPathComponent.ns.deletingPathExtension let terminalPath = "\(folder)/\(schemeName).terminal" convertToTerminalColors(itermFile: path, terminalFile: terminalPath) } } else { print("usage: iTermColorsToTerminalColors FILE.itermcolors [...]") } -
leonbreedt created this gist
Oct 19, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,175 @@ #!/usr/bin/xcrun swift import AppKit enum iTermColors: String { case Ansi0 = "Ansi 0 Color" case Ansi1 = "Ansi 1 Color" case Ansi2 = "Ansi 2 Color" case Ansi3 = "Ansi 3 Color" case Ansi4 = "Ansi 4 Color" case Ansi5 = "Ansi 5 Color" case Ansi6 = "Ansi 6 Color" case Ansi7 = "Ansi 7 Color" case Ansi8 = "Ansi 8 Color" case Ansi9 = "Ansi 9 Color" case Ansi10 = "Ansi 10 Color" case Ansi11 = "Ansi 11 Color" case Ansi12 = "Ansi 12 Color" case Ansi13 = "Ansi 13 Color" case Ansi14 = "Ansi 14 Color" case Ansi15 = "Ansi 15 Color" case CursorText = "Cursor Text Color" case SelectedText = "Selected Text Color" case Foreground = "Foreground Color" case Background = "Background Color" case Bold = "Bold Color" case Selection = "Selection Color" case Cursor = "Cursor Color" } enum TerminalColors: String { case AnsiBlack = "ANSIBlackColor" case AnsiRed = "ANSIRedColor" case AnsiGreen = "ANSIGreenColor" case AnsiYellow = "ANSIYellowColor" case AnsiBlue = "ANSIBlueColor" case AnsiMagenta = "ANSIMagentaColor" case AnsiCyan = "ANSICyanColor" case AnsiWhite = "ANSIWhiteColor" case AnsiBrightBlack = "ANSIBrightBlackColor" case AnsiBrightRed = "ANSIBrightRedColor" case AnsiBrightGreen = "ANSIBrightGreenColor" case AnsiBrightYellow = "ANSIBrightYellowColor" case AnsiBrightBlue = "ANSIBrightBlueColor" case AnsiBrightMagenta = "ANSIBrightMagentaColor" case AnsiBrightCyan = "ANSIBrightCyanColor" case AnsiBrightWhite = "ANSIBrightWhiteColor" case Background = "BackgroundColor" case Text = "TextColor" case BoldText = "BoldTextColor" case Selection = "SelectionColor" case Cursor = "CursorColor" } let iTermColor2TerminalColor = [ iTermColors.Ansi0: TerminalColors.AnsiBlack, iTermColors.Ansi1: TerminalColors.AnsiRed, iTermColors.Ansi2: TerminalColors.AnsiGreen, iTermColors.Ansi3: TerminalColors.AnsiYellow, iTermColors.Ansi4: TerminalColors.AnsiBlue, iTermColors.Ansi5: TerminalColors.AnsiMagenta, iTermColors.Ansi6: TerminalColors.AnsiCyan, iTermColors.Ansi7: TerminalColors.AnsiWhite, iTermColors.Ansi8: TerminalColors.AnsiBrightBlack, iTermColors.Ansi9: TerminalColors.AnsiBrightRed, iTermColors.Ansi10: TerminalColors.AnsiBrightGreen, iTermColors.Ansi11: TerminalColors.AnsiBrightYellow, iTermColors.Ansi12: TerminalColors.AnsiBrightBlue, iTermColors.Ansi13: TerminalColors.AnsiBrightMagenta, iTermColors.Ansi14: TerminalColors.AnsiBrightCyan, iTermColors.Ansi15: TerminalColors.AnsiBrightWhite, iTermColors.Background: TerminalColors.Background, iTermColors.Foreground: TerminalColors.Text, iTermColors.Selection: TerminalColors.Selection, iTermColors.Bold: TerminalColors.BoldText, iTermColors.Cursor: TerminalColors.Cursor, ] struct iTermColorComponent { static let Red = "Red Component" static let Green = "Green Component" static let Blue = "Blue Component" } func itermColorSchemeToTerminalColorScheme(itermColorScheme: NSDictionary, #name: String) -> NSDictionary { var terminalColorScheme: [String: AnyObject] = [ "name" : name, "type" : "Window Settings", "ProfileCurrentVersion" : 2.04, "columnCount": 90, "rowCount": 50, ] if let font = archivedFontWithName("PragmataPro", 14) { terminalColorScheme["Font"] = font } for (rawKey, rawValue) in itermColorScheme { if let name = rawKey as? String { if let key = iTermColors(rawValue: name) { if let terminalKey = iTermColor2TerminalColor[key] { if let itermDict = rawValue as? NSDictionary { let (r, g, b) = ( floatValue(itermDict[iTermColorComponent.Red]), floatValue(itermDict[iTermColorComponent.Green]), floatValue(itermDict[iTermColorComponent.Blue])) let color = NSColor(deviceRed: r, green: g, blue: b, alpha: 1) let colorData = NSKeyedArchiver.archivedDataWithRootObject(color) terminalColorScheme[terminalKey.rawValue] = colorData } } } } } return terminalColorScheme } func archivedFontWithName(name: String, size: CGFloat) -> NSData? { if let font = NSFont(name: name, size: size) { return NSKeyedArchiver.archivedDataWithRootObject(font) } return nil } func floatValue(value: AnyObject?) -> CGFloat { if let num = value as? CGFloat { return num } return 0 } func arguments() -> [String] { var args: [String] = [] for i in 1...C_ARGC { if let arg = String.fromCString(C_ARGV[Int(i)]) { args.append(arg) } } return args } extension String { var fullPath: String { get { let path = stringByStandardizingPath var directory = path.stringByDeletingLastPathComponent if countElements(directory) == 0 { directory = NSFileManager.defaultManager().currentDirectoryPath } return directory.stringByAppendingPathComponent(path) } } } func convertToTerminalColors(itermFile: String, terminalFile: String) { if let itermScheme = NSDictionary(contentsOfFile: itermFile) { println("converting \(itermFile) -> \(terminalFile)") let terminalName = terminalFile.lastPathComponent.stringByDeletingPathExtension let terminalScheme = itermColorSchemeToTerminalColorScheme(itermScheme, name: terminalName) terminalScheme.writeToFile(terminalFile, atomically: true) } else { println("unable to load \(itermFile)") } } let args = arguments() if args.count > 0 { for itermFile in args { let path = itermFile.fullPath let folder = path.stringByDeletingLastPathComponent let schemeName = path.lastPathComponent.stringByDeletingPathExtension let terminalPath = "\(folder)/\(schemeName).terminal" convertToTerminalColors(path, terminalPath) } } else { println("usage: iTermColorsToTerminalColors FILE.itermcolors [...]") }