diff --git a/Jump.Location/CommandController.cs b/Jump.Location/CommandController.cs index c7f31b1..5fb7a4d 100644 --- a/Jump.Location/CommandController.cs +++ b/Jump.Location/CommandController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Threading; @@ -12,7 +13,7 @@ class CommandController private bool needsToSave; private DirectoryWaitPeriod waitPeriod; - public CommandController(IDatabase database, IFileStoreProvider fileStore) + internal CommandController(IDatabase database, IFileStoreProvider fileStore) { this.database = database; this.fileStore = fileStore; @@ -20,9 +21,11 @@ public CommandController(IDatabase database, IFileStoreProvider fileStore) thread.Start(); } - public CommandController(string path) - :this(new Database(), new FileStoreProvider(path)) + public static CommandController Create(string path) { + var fileStore = new FileStoreProvider(path); + var database = fileStore.Revive(); + return new CommandController(database, fileStore); } public void UpdateLocation(string fullName) @@ -53,7 +56,7 @@ private void SaveLoop() } catch(Exception e) { - Console.Error.WriteLine("Jump-Location received {0}: {1}", e.GetType().Name, e.Message); + EventLog.WriteEntry("Application", string.Format("{0}\r\n{1}", e, e.StackTrace)); } } else Thread.Sleep(0); diff --git a/Jump.Location/JumpLocationCommand.cs b/Jump.Location/JumpLocationCommand.cs index d7ad8a1..d20e33a 100644 --- a/Jump.Location/JumpLocationCommand.cs +++ b/Jump.Location/JumpLocationCommand.cs @@ -1,5 +1,4 @@ -using System.Linq; -using System.Management.Automation; +using System.Management.Automation; namespace Jump.Location { @@ -7,13 +6,13 @@ namespace Jump.Location public class JumpLocationCommand : PSCmdlet { private static bool _hasRegisteredDirectoryHook; - private static readonly CommandController Controller = new CommandController(@"C:\Users\Kerianne\jump-location.txt"); + private static readonly CommandController Controller = CommandController.Create(@"C:\Users\Kerianne\jump-location.txt"); /* * x1. Figure out how long they stay in the directory * x2. Log occurences of filename / weight * x3. Tail matches - search matches beginning of last segment of path - * 4. Make MSI installer for easy use + * x4. Make MSI installer for easy use * 5. Weighting algorithm - match what Autojump does to increase weights * 6. Match what Autojump does to degrade weights * 7. Multiple args - last arg is a tail match, previous args match previous segments @@ -43,7 +42,7 @@ protected override void BeginProcessing() InvokeCommand.InvokeScript(@"Set-PSBreakpoint -Variable pwd -Mode Write -Action { [Jump.Location.JumpLocationCommand]::UpdateTime($($(Get-Item -Path $(Get-Location))).PSPath); - }", "hello Jim"); + }"); _hasRegisteredDirectoryHook = true; } diff --git a/Readme.md b/Readme.md index cd84566..b2c1eb5 100644 --- a/Readme.md +++ b/Readme.md @@ -4,13 +4,12 @@ Jump-Location: A cd that learns If you spend any time in a console you know that `cd` is by far the most common command that you issue. You'll open up a console to `C:\Users\me` or `C:\Windows\system32` and then issue a `cd C:\work\Website`. -`Jump-Location` is a cmdlet lets you issue a `Jump-Location we` to jump +`Jump-Location` is a cmdlet lets you issue a `j we` to jump directly to `C:\work\Website`. It learns your behavior by keeping track of how long you spend in certain -directories and favoring them over the ones you don't care about. You don't -have to -use `Jump-Location` as a replacement for `cd`. Use `cd` to go local, and +directories and favoring them over the ones you don't care about. You don't +have to use `Jump-Location` as a replacement for `cd`. Use `cd` to go local, and use `Jump-Location` to jump further away. `Jump-Location` is a powershell implementation of