;; -> init ShellApp := ComObjCreate("Shell.Application") GroupAdd, Explorer, ahk_class CabinetWClass GroupAdd, Explorer, ahk_class ExploreWClass GroupAdd, Desktop, ahk_class Progman GroupAdd, Desktop, ahk_class WorkerW GroupAdd, ExplorerDesktop, ahk_class CabinetWClass GroupAdd, ExplorerDesktop, ahk_class ExploreWClass GroupAdd, ExplorerDesktop, ahk_class Progman GroupAdd, ExplorerDesktop, ahk_class WorkerW ;; -> library Explorer(hwnd := "") { global ShellApp if (hwnd = "") WinGet, hwnd, id, A for window in ShellApp.Windows if (window.hwnd = hwnd) return window return -1 } ExplorerPath() { WinGetClass, cls, A if (cls = "Progman" or cls = "WorkerW") return %A_Desktop% else return Explorer().Document.Folder.Self.path } ;; -> body ;; Explorer/Desktop hotkeys --------------------------------------------------- #IfWinActive ahk_group ExplorerDesktop ; Open new window/command prompt ^n::Run, % "explorer /n,""" ExplorerPath() """" ^p::Run, % "cmd /k cd /d """ ExplorerPath() """" +^p:: path := ExplorerPath() Run, % "C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Visual Studio 2010 Express\Visual Studio Command Prompt (2010).lnk" WinWait, ahk_class ConsoleWindowClass SendInput, % "cd " path "{Return}" return ; Create new folder/file ^+n:: FileCreateDir, % ExplorerPath() "\New Folder" SendInput, {F5}New Folder{F2} return ^!n:: FileAppend,, % ExplorerPath() "\New Text Document.txt" SendInput, {F5}New Text Document.txt{F2} return ;; Explorer hotkeys ----------------------------------------------------------- ; Edit file #IfWinActive LWin & LButton:: MouseGetPos,,, hwnd DllCall("SetForegroundWindow", "UInt", hwnd) if (not DoubleClick()) ; see tt.doubleclick.ahk return if (not WinActive("ahk_group Explorer")) { SendInput, {Click} return } ; fall through to next hotkey #IfWinActive ahk_group Explorer #NumPadEnter:: #Enter:: i := Explorer().Document.FocusedItem if (i.IsFolder) return ShellApp.ShellExecute(i.path, "", "", "Edit", 1) return ; Directory navigation LAlt & Up:: RAlt & Up:: e := Explorer() path := e.Document.Folder.Self.path if (InStr(path, "::{") = 1) return slash := InStr(path, "\", 0, 0) if (slash = StrLen(path)) slash := InStr(path, "\", 0, 0, 2) if (slash = 0) parent = ::{20D04FE0-3AEA-1069-A2D8-08002B30309D} ; My Computer else parent := SubStr(path, 1, slash) e.Navigate(parent) return LAlt & Down:: RAlt & Down:: path := ExplorerPath() if (InStr(path, "::{") = 1) return Explorer().Navigate(path) ; go to real path of folder return ; Toggle hidden status ^h:: SSF_SHOWALLOBJECTS := 0x0001 VarSetCapacity(SHELLSTATE, 32, 0) DllCall("Shell32\SHGetSetSettings", "Ptr", &SHELLSTATE, "UInt", SSF_SHOWALLOBJECTS, "Int", false) NumPut(NumGet(SHELLSTATE) ^ (1 << 0), SHELLSTATE,, "Int") DllCall("Shell32\SHGetSetSettings", "Ptr", &SHELLSTATE, "UInt", SSF_SHOWALLOBJECTS, "Int", true) WinGet, win, List, ahk_group Explorer Loop, % win PostMessage, 0x111, 41504,,, % "ahk_id " win%A_Index% ; refresh return ; Sort and display options ^q::ExplorerFolderView("name") ^w::ExplorerFolderView("modified") ^e::ExplorerFolderView("type") ^t::ExplorerFolderView("created") ^g::ExplorerFolderView("groups") ^s::ExplorerFolderView("tiles") ^d::ExplorerFolderView("icons") ^+d::ExplorerFolderView("thumbnails") ^f::ExplorerFolderView("details") ^+f::ExplorerFolderView("list") ^!q::ExplorerFolderView("name", true) ^!w::ExplorerFolderView("modified", true) ^!e::ExplorerFolderView("type", true) ^!t::ExplorerFolderView("created", true) ^!g::ExplorerFolderView("groups", true) ^!s::ExplorerFolderView("tiles", true) ^!d::ExplorerFolderView("icons", true) ^!+d::ExplorerFolderView("thumbnails", true) ^!f::ExplorerFolderView("details", true) ^!+f::ExplorerFolderView("list", true) #IfWinActive ;; -> library ExplorerFolderView(view, children := false) { if (view = "name") n := {m: 30210, d: -1} else if (view = "modified") n := {m: 30213, d: -1} else if (view = "type") n := {m: 30212, d: -1} else if (view = "created") n := {m: 30214, d: -1} else if (view = "groups") n := {m: 30209, d: -1} else if (view = "tiles") n := {m: 28718, d: 6} else if (view = "icons") n := {m: 28713, d: 1} else if (view = "thumbnails") n := {m: 28717, d: 5} else if (view = "details") n := {m: 28716, d: 4} else if (view = "list") n := {m: 28715, d: 3} PostMessage, 0x111, % n.m, 0,, A ; change current folder return if (not children or m.d = -1) return old := A_BatchLines SetBatchLines, -1 Loop, Files, % ExplorerPath() "\*", D { MsgBox, % A_LoopFileFullPath } SetBatchLines, % old } ;; Git mode ------------------------------------------------------------------- ;; -> library q(s) { return """" s """" } ;; -> body #IfWinActive ahk_group Explorer #g:: ToolTip, ... SendInput, {Blind}{LWin Up} Input, k, C L1 ex := Explorer() i := ex.Document.FocusedItem.path path := ex.Document.Folder.Self.path slash := InStr(path, "\", 0, 0) basename := SubStr(path, slash + 1) if (k = "a") Run, % "cmd /c cd "q(path)" & git add "q(i)" && git status & pause" if (k = "c") Run, % "cmd /c cd "q(path)" & git commit & pause" if (k = "d") Run, % "cmd /c cd "q(path)" & git diff "q(i)" & pause" if (k = "f") Run, % "cmd /c cd "q(path)" & git diff & pause" if (k = "m") Run, % "cmd /c cd "q(path)" & git commit --amend & pause" if (k = "p") Run, % "cmd /c cd "q(path)" & git push origin "q(basename)" & pause" if (k = "r") Run, % "cmd /c cd "q(path)" & git reset "q(i)" && git status & pause" if (k = "s") Run, % "cmd /c cd "q(path)" & git status & pause" ToolTip return #IfWinActive