;; -> 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 } RunAsUser(cmd*) { global ShellApp return ShellApp.Windows.FindWindowSW(0, 0, 8, 0, 1).Document.Application.ShellExecute(cmd*) } ;; -> body ;; Explorer/Desktop hotkeys --------------------------------------------------- #IfWinActive ahk_group ExplorerDesktop ; Reload icons ^+r::DllCall("Shell32\SHChangeNotify", UInt, 0x08000000, UInt, 0, UIntP, 0, UIntP, 0) ; Open new window/command prompt ^n::Run, % "explorer /n,""" ExplorerPath() """" ^p::RunAsUser("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 /d " path "{Return}" return ; Create new file ^!n:: path := ExplorerPath() "\" pre := "Nytt textdokument" post := ".txt" if (FileExist(path pre post)) { n := 2 while (FileExist(path pre " (" n ")" post)) n += 1 name := pre " (" n ")" post } else name := pre post FileAppend,, % name SendInput, {Esc}{F5} Sleep, 80 SendInput, % name "{F2}" return ;; Explorer hotkeys ----------------------------------------------------------- ; Edit file #IfWinActive LWin & LButton:: *#LButton:: MouseGetPos,,, hwnd if (not DoubleClick() or not WinActive("ahk_group Explorer")) ; see tt.doubleclick.ahk { SendInput, {Click} return } ; fall through to next hotkey #IfWinActive ahk_group Explorer *#NumPadEnter:: *#Enter:: i := Explorer().Document.FocusedItem if (i.IsFolder) return if (GetKeyState("Shift")) ShellApp.ShellExecute(i.path, "", "", "Edit2", 1) else ShellApp.ShellExecute(i.path, "", "", "Edit", 1) return ; Copy file path ^+c:: e := Explorer() r := "" items := e.Document.SelectedItems if (items.Count() > 1) for item in items r .= """" item.path """ " else for item in items r := item.path if (r = "") r := e.Document.Folder.Self.path clipboard := r return ; Directory navigation 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 (Windows XP) ;^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") #IfWinActive ;; -> library ExplorerFolderView(view) { 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 return } ;; Git hotkeys ---------------------------------------------------------------- ;; -> library q(s) { return """" s """" } qp() { return """" Explorer().Document.Folder.Self.path """" } qip() { r := "" for item in Explorer().Document.SelectedItems r .= """" item.path """ " return r } basename(s) { slash := InStr(path, "\", 0, 0) return SubStr(path, slash + 1) } ;; -> body #IfWinActive ahk_group Explorer !c::Run, % "cmd /c cd "qp()" & git commit & pause" !+c::Run, % "cmd /c cd "qp()" & git commit --amend & pause" !^c::Run, % "cmd /c cd "qp()" & git commit -a & pause" !^+c::Run, % "cmd /c cd "qp()" & git commit -a --amend & pause" !p::Run, % "cmd /c cd "qp()" & git push & pause" !s::Run, % "cmd /c cd "qp()" & git status & pause" !a:: qip := qip() if (qip = "") Run, % "cmd /c cd "qp()" & git add . && git status & pause" else Run, % "cmd /c cd "qp()" & git add " qip " && git status & pause" return !+a:: qip := qip() if (qip = "") Run, % "cmd /c cd "qp()" & git add -p . && git status & pause" else Run, % "cmd /c cd "qp()" & git add -p " qip " && git status & pause" return !f:: qip := qip() if (qip = "") Run, % "cmd /c cd "qp()" & git diff & pause" else Run, % "cmd /c cd "qp()" & git diff " qip " & pause" return !i:: qip := qip() if (qip = "") Run, % "cmd /c cd "qp()" & git diff HEAD~1 HEAD & pause" else Run, % "cmd /c cd "qp()" & git diff HEAD~1 HEAD " qip " & pause" return !l:: qip := qip() if (qip = "") Run, % "cmd /c cd "qp()" & git log & pause" else Run, % "cmd /c cd "qp()" & git log " qip " & pause" return !r:: qip := qip() if (qip = "") Run, % "cmd /c cd "qp()" & git reset . && git status & pause" else Run, % "cmd /c cd "qp()" & git reset " qip " && git status & pause" return #IfWinActive