-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
231 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// CopyPathAction.swift | ||
// quick-symlink | ||
// | ||
// Created by Alexander A. Kropotin on 15/07/2021. | ||
// Copyright © 2021 Alexander A. Kropotin. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import FinderSync | ||
|
||
public class CopyPathAction: QuickSymlinkAction { | ||
|
||
private var finderController: FIFinderSyncController; | ||
|
||
public init() { | ||
self.finderController = FIFinderSyncController.default(); | ||
} | ||
|
||
public func execute() { | ||
//Get all selected path | ||
guard let target = self.finderController.selectedItemURLs() else { | ||
NSLog("FinderSync() failed to obtain targeted URLs: %@"); | ||
|
||
return; | ||
} | ||
|
||
// Append all selected paths to string | ||
var paths = "" | ||
for path in target { | ||
paths.append(contentsOf: path.relativePath); | ||
paths.append(";"); | ||
} | ||
paths.removeLast(); | ||
|
||
//Copy path list to clipboard | ||
let pasteboard = NSPasteboard.general; | ||
pasteboard.declareTypes([NSPasteboard.PasteboardType.string], owner: nil); | ||
pasteboard.setString(paths, forType: NSPasteboard.PasteboardType.string); | ||
} | ||
} |
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,45 @@ | ||
// | ||
// PasteSymlinkAction.swift | ||
// quick-symlink | ||
// | ||
// Created by Alexander A. Kropotin on 15/07/2021. | ||
// Copyright © 2021 Alexander A. Kropotin. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import FinderSync | ||
|
||
public class PasteLinkAction: QuickSymlinkAction { | ||
|
||
private var finderController: FIFinderSyncController; | ||
|
||
public init() { | ||
self.finderController = FIFinderSyncController.default(); | ||
} | ||
|
||
public func execute() { | ||
//Get selected folder path | ||
guard let target = self.finderController.targetedURL() else { | ||
NSLog("FinderSync() failed to obtain targeted URL: %@"); | ||
|
||
return; | ||
} | ||
|
||
let pathsFromClipboard = NSPasteboard.general.string(forType: NSPasteboard.PasteboardType.string) ?? ""; | ||
if pathsFromClipboard.isEmpty { | ||
return; | ||
} | ||
|
||
let paths = pathsFromClipboard.components(separatedBy: ";"); | ||
for path in paths { | ||
let pathUrl = URL(fileURLWithPath: path); | ||
let targetPath = self.getTargetPath(pathUrl, to: target); | ||
|
||
do { | ||
try FileManager.default.createSymbolicLink(at: targetPath!, withDestinationURL: URL(fileURLWithPath: path)); | ||
} catch let error as NSError { | ||
NSLog("FileManager.createSymbolicLink() failed to create file: %@", error.description as NSString); | ||
} | ||
} | ||
} | ||
} |
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,40 @@ | ||
// | ||
// QuickSymlinkAction.swift | ||
// quick-symlink | ||
// | ||
// Created by Alexander A. Kropotin on 15/07/2021. | ||
// Copyright © 2021 Alexander A. Kropotin. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol QuickSymlinkAction { | ||
|
||
func execute(); | ||
} | ||
|
||
internal extension QuickSymlinkAction { | ||
|
||
internal func getTargetPath(_ from: URL!, to: URL!) -> URL! { | ||
let originSourceName = from.absoluteURL.deletingPathExtension().lastPathComponent; | ||
let fileType = from.absoluteURL.pathExtension; | ||
|
||
var fileExtention = fileType; | ||
if !fileType.isEmpty { | ||
fileExtention = ".\(fileType)" | ||
} | ||
|
||
var fileName = "\(originSourceName)\(fileExtention)"; | ||
var counter = 1 | ||
var targetPath = to; | ||
targetPath = targetPath?.appendingPathComponent(fileName); | ||
|
||
while FileManager.default.fileExists(atPath: (targetPath?.path)!) { | ||
fileName = "\(originSourceName)-\(counter)\(fileExtention)"; | ||
counter += 1; | ||
targetPath = to.appendingPathComponent(fileName); | ||
} | ||
|
||
return targetPath!; | ||
} | ||
} |
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,46 @@ | ||
// | ||
// ReplaceWithLinkAction.swift | ||
// quick-symlink | ||
// | ||
// Created by Alexander A. Kropotin on 15/07/2021. | ||
// Copyright © 2021 Alexander A. Kropotin. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import FinderSync | ||
|
||
public class ReplaceWithLinkAction: QuickSymlinkAction { | ||
|
||
private var finderController: FIFinderSyncController; | ||
|
||
public init() { | ||
self.finderController = FIFinderSyncController.default(); | ||
} | ||
|
||
public func execute() { | ||
//Get selected folder path | ||
guard let target = self.finderController.targetedURL() else { | ||
NSLog("FinderSync() failed to obtain targeted URL: %@"); | ||
|
||
return; | ||
} | ||
|
||
let pathsFromClipboard = NSPasteboard.general.string(forType: NSPasteboard.PasteboardType.string) ?? ""; | ||
if pathsFromClipboard.isEmpty { | ||
return; | ||
} | ||
|
||
let paths = pathsFromClipboard.components(separatedBy: ";"); | ||
for path in paths { | ||
let pathUrl = URL(fileURLWithPath: path); | ||
let targetPath = self.getTargetPath(pathUrl, to: target); | ||
|
||
do { | ||
try FileManager.default.moveItem(at: pathUrl, to: targetPath!); | ||
try FileManager.default.createSymbolicLink(at: pathUrl, withDestinationURL: targetPath!); | ||
} catch let error as NSError { | ||
NSLog("FileManager.createSymbolicLink() failed to create file: %@", error.description as NSString); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.