Skip to content

Commit

Permalink
feat: make bottle paths look pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaiibuzzle committed Jun 15, 2023
1 parent eb25afe commit 30c6f30
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions Harbor/Extensions/URLExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// URLExtensions.swift
// Harbor
//
// Created by Venti on 15/06/2023.
//

import Foundation

extension URL {
var prettyFileUrl: String {
if !self.isFileURL {
return self.absoluteString
}
guard var prettyPath = self.path.removingPercentEncoding else {
return self.path
}

if path.hasPrefix("/Users") {
// Remove /Users/<username> and replace with ~
prettyPath = prettyPath.replacingOccurrences(of: #"/Users/[^/]+/"#,
with: "~/", options: .regularExpression)
}

return prettyPath
}
}
4 changes: 2 additions & 2 deletions Harbor/Views/BottleManagementView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct BottleManagementView: View {

Table(bottles, selection: $selectedBottle, sortOrder: $sortOrder) {
TableColumn("home.table.name", value: \.name)
TableColumn("home.table.path", value: \.path.relativeString)
TableColumn("home.table.path", value: \.path.prettyFileUrl)
TableColumn("home.table.primaryApp", value: \.primaryApplicationPath)
}
.padding()
Expand Down Expand Up @@ -100,7 +100,7 @@ struct BottleManagementView: View {
alert.alertStyle = .critical
let checkbox = NSButton(checkboxWithTitle:
String(format: String(localized: "home.alert.deletePath %@"),
thisBottle.path.absoluteString), target: nil, action: nil)
thisBottle.path.prettyFileUrl), target: nil, action: nil)
checkbox.state = .on
alert.accessoryView = checkbox
alert.addButton(withTitle: String(localized: "btn.delete"))
Expand Down

0 comments on commit 30c6f30

Please sign in to comment.