aboutsummaryrefslogtreecommitdiff
path: root/tt.programs.explorer.ahk
blob: 3bebd6d2384f6ba66ee7db0c2e85c9dc57ec190b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
;; -> 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

; 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::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 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

*#LButton::
MouseGetPos,,, hwnd
DllCall("SetForegroundWindow", "UInt", 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 & 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 (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