interplane.Get Omega
Read in your language

hop

Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key.

Brought by drakestapleton

branch main Branches Tags History

hop / Omega / tests / ui-index / main.swift

29 lines · 1540 bytes Raw Blame History
1import Foundation
2
3// Builds a file index exactly as Hop does: the loop below is the one of Sources/FileIndex.swift (rebuild), given
4// the folders and the names to skip on the command line. Omega/tests/check-ui.sh compares what it writes, byte
5// for byte, with what the Omega program writes for the same folders.
6// ui-index OUT ROOT [SKIP-NAME ...]
7let a = CommandLine.arguments
8guard a.count >= 3 else { FileHandle.standardError.write(Data("usage: ui-index OUT ROOT [SKIP-NAME ...]\n".utf8)); exit(2) }
9let roots = [a[2]], skip = Set(a.dropFirst(3))
10var out = Data()
11let keys: [URLResourceKey] = [.isDirectoryKey, .isPackageKey, .isSymbolicLinkKey]
12var seen = 0
13for root in roots {
14 guard let en = FileManager.default.enumerator(at: URL(fileURLWithPath: root), includingPropertiesForKeys: keys,
15 options: [.skipsHiddenFiles], errorHandler: { _, _ in true }) else { continue }
16 for case let u as URL in en {
17 let name = u.lastPathComponent
18 let v = try? u.resourceValues(forKeys: Set(keys))
19 if v?.isDirectory == true {
20 if skip.contains(name) || v?.isSymbolicLink == true { en.skipDescendants(); continue }
21 if v?.isPackage == true { en.skipDescendants() } // .app, .pages, ... count as one item
22 }
23 out.append(contentsOf: Array(u.path.utf8)); out.append(10)
24 seen += 1
25 if seen >= 3_000_000 { break }
26 }
27}
28try! out.write(to: URL(fileURLWithPath: a[1]), options: .atomic)
29print("indexed \(seen) items")