1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00

GH-232 Always send cwd

This commit is contained in:
Tae Won Ha 2016-08-21 14:02:20 +02:00
parent 560b522310
commit 818f61323b
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
2 changed files with 24 additions and 15 deletions

View File

@ -14,8 +14,8 @@ private let cwdPrefix = "cwd="
private enum VimRUrlAction: String {
case activate = "activate"
case open = "open"
case newWindows = "new-windows"
case separateWindows = "separate-windows"
case newWindow = "open-in-new-window"
case separateWindows = "open-in-separate-windows"
}
@NSApplicationMain
@ -97,7 +97,7 @@ extension AppDelegate {
let appleEventManager = NSAppleEventManager.sharedAppleEventManager()
appleEventManager.setEventHandler(self,
andSelector: #selector(AppDelegate.handleGetURLEvent(_:withReplyEvent:)),
andSelector: #selector(AppDelegate.handleGetUrlEvent(_:withReplyEvent:)),
forEventClass: UInt32(kInternetEventClass),
andEventID: UInt32(kAEGetURL))
}
@ -156,7 +156,7 @@ extension AppDelegate {
// MARK: - AppleScript
extension AppDelegate {
func handleGetURLEvent(event: NSAppleEventDescriptor, withReplyEvent: NSAppleEventDescriptor) {
func handleGetUrlEvent(event: NSAppleEventDescriptor, withReplyEvent: NSAppleEventDescriptor) {
guard let urlString = event.paramDescriptorForKeyword(UInt32(keyDirectObject))?.stringValue else {
return
}
@ -195,7 +195,17 @@ extension AppDelegate {
.flatMap { $0.without(prefix: cwdPrefix).stringByRemovingPercentEncoding }
.first ?? NSHomeDirectory()
NSLog("\(#function): \(action) in \(cwd): \(fileNames)")
NSLog("\(#function): \(action) in '\(cwd)': \(fileNames)")
switch action {
case .open:
return
case .newWindow:
return
case .separateWindows:
return
default:
return
}
}
}

View File

@ -3,6 +3,7 @@
import urllib
import subprocess
import argparse
import os
from pprint import pprint
@ -15,13 +16,11 @@ def call_open(arg, dry_run=False):
def vimr(action, args=None, dry_run=False):
files = args.file
cwd = args.cwd
query_params = {}
if cwd:
query_params["cwd"] = args.cwd
query_params = { "cwd": args.cwd or os.getcwd() }
if files:
query_params["file"] = args.file
query_params["file"] = files
url = "vimr://{0}?{1}".format(action, urllib.urlencode(query_params, True))
call_open(url, dry_run)
@ -30,8 +29,8 @@ def vimr(action, args=None, dry_run=False):
class Action:
ACTIVATE = "activate"
OPEN = "open"
NEW_WINDOWS = "new-windows"
SEPARATE_WINDOWS = "separate-windows"
NEW_WINDOW = "open-in-new-window"
SEPARATE_WINDOWS = "open-in-separate-windows"
parser = argparse.ArgumentParser(description="Open files in VimR. By default all files are open in tabs in the front "
@ -41,7 +40,7 @@ parser.add_argument("--dry-run", action="store_true", dest="dry_run", help="Just
parser.add_argument("--cwd", action="store", help="Set the working directory.")
group = parser.add_mutually_exclusive_group()
# no option => Open files in tabs in the front most window.
group.add_argument("-n", action="store_true", dest="new_windows", help="Open files in tabs in a new window.")
group.add_argument("-n", action="store_true", dest="new_window", help="Open files in tabs in a new window.")
group.add_argument("-s", action="store_true", dest="separate_windows", help="Open files in separate windows.")
parser.add_argument("file", nargs="*")
args = parser.parse_args()
@ -49,8 +48,8 @@ dry_run = args.dry_run
if not args.file:
action = Action.ACTIVATE
elif args.new_windows:
action = Action.NEW_WINDOWS
elif args.new_window:
action = Action.NEW_WINDOW
elif args.separate_windows:
action = Action.SEPARATE_WINDOWS
else: