-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandLineHere.ahk
203 lines (179 loc) · 6.19 KB
/
CommandLineHere.ahk
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
SetTitleMatchMode RegEx
return
; Stuff to do when Windows Explorer is open
;
; '!'
; This tells AutoIt to send an ALT keystroke, therefore Send("This is text!a") would send the keys "This is text" and then press "ALT+a".
;
; N.B. Some programs are very choosy about capital letters and ALT keys, i.e., "!A" is different from "!a". The first says ALT+SHIFT+A, the second is ALT+a. If in doubt, use lowercase!
;
; '+'
; This tells AutoIt to send a SHIFT keystroke; therefore, Send("Hell+o") would send the text "HellO". Send("!+a") would send "ALT+SHIFT+a".
;
; '^'
; This tells AutoIt to send a CONTROL keystroke; therefore, Send("^!a") would send "CTRL+ALT+a".
;
; N.B. Some programs are very choosy about capital letters and CTRL keys, i.e., "^A" is different from "^a". The first says CTRL+SHIFT+A, the second is CTRL+a. If in doubt, use lowercase!
;
; '#'
; The hash now sends a Windows keystroke; therefore, Send("#r") would send Win+r which launches the Run() dialog box.
CapsLock::Esc
ScrollLock::CapsLock
#+q::!F4
#IfWinActive ahk_class ExploreWClass|CabinetWClass
^#c::
RefreshEnvironment()
OpenOniInCurrent()
return
#c::
RefreshEnvironment()
OpenTerminalInCurrent()
return
#+c::
RefreshEnvironment()
OpenCodeInCurrent()
return
^+m::
RefreshEnvironment()
OpenMergeInCurrent()
return
#IfWinActive
GetCurrentDirectory()
{
SetTitleMatchMode, 2
WinGetText, out,A
StringSplit, StringArray, out, ["`r","`n","`r`n"]
Loop, %StringArray0%
{
this_string := StringArray%a_index%
IfInString, this_string, :
{
this_string := Trim(StrReplace(this_string, "Adresse:", ""))
this_string := Trim(StrReplace(this_string, "Address:", ""))
return %this_string%
}
}
}
; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenOniInCurrent()
{
; strip to bare address
full_path := GetCurrentDirectory()
IfExist, %LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe
Run, C:\Program Files\Onivim2\Oni2.exe "%full_path%"
else
OpenCodeInCurrent()
}
; Opens the command shell 'cmd' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenTerminalInCurrent()
{
; strip to bare address
full_path := GetCurrentDirectory()
IfExist, %LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe
Run, "%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe" -d "%full_path%"
else
Run, cmd /K cd /D "%full_path%"
}
; Opens sublime merge in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenMergeInCurrent()
{
; strip to bare address
full_path := GetCurrentDirectory()
IfExist, C:\Program Files\Sublime Merge\smerge.exe
Run, "C:\Program Files\Sublime Merge\smerge.exe" "%full_path%"
else
Run, smerge.exe "%full_path%"
}
; Opens the command shell 'code' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenCodeInCurrent()
{
; strip to bare address
full_path := GetCurrentDirectory()
IfExist, C:\Program Files\Microsoft VS Code\Code.exe
Run, "C:\Program Files\Microsoft VS Code\Code.exe" "%full_path%"
else
IfExist, C:\Program Files (x86)\Microsoft VS Code\Code.exe
Run, "C:\Program Files (x86)\Microsoft VS Code\Code.exe" "%full_path%"
else
Run, "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" "%full_path%"
}
; Opens the command shell 'code' in the directory browsed in Explorer.
; Note: expecting to be run when the active window is Explorer.
;
OpenToolManInCurrent()
{
; strip to bare address
full_path := GetCurrentDirectory()
IfExist, c:\Tools\Toolman.exe
Run, "c:\Tools\Toolman.exe" "%full_path%"
}
RefreshEnvironment()
{
; load the system-wide environment variables first in case there are user-level
; variables with the same name (since they override the system definitions).
; treat PATH and PATHEXT special - we must contactenate the user and system values.
sysPATH := ""
sysPATHEXT := ""
Loop, HKLM, SYSTEM\CurrentControlSet\Control\Session Manager\Environment, 0, 0
{
RegRead, vEnvValue
If (A_LoopRegType == "REG_EXPAND_SZ") {
If (!ExpandEnvironmentStrings(vEnvValue)) {
Return False
}
}
EnvSet, %A_LoopRegName%, %vEnvValue%
if (A_LoopRegName = "PATH") {
sysPATH := vEnvValue
}
else if (A_LoopRegName = "PATHEXT") {
sysPATHEXT := vEnvValue
}
}
; now load the user level environment variables
Loop, HKCU, Environment, 0, 0
{
RegRead, vEnvValue
If (A_LoopRegType == "REG_EXPAND_SZ") {
If (!ExpandEnvironmentStrings(vEnvValue)) {
Return False
}
}
envVal := vEnvValue
if (A_LoopRegName = "PATH") {
envVal := envVal . ";" . sysPATH
}
else if (A_LoopRegName = "PATHEXT") {
envVal := envVal . ";" . sysPATHEXT
}
EnvSet, %A_LoopRegName%, %envVal%
}
; return success.
Return True
}
ExpandEnvironmentStrings(ByRef vInputString)
{
; get the required size for the expanded string
vSizeNeeded := DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Int", 0, "Int", 0)
If (vSizeNeeded == "" || vSizeNeeded <= 0)
return False ; unable to get the size for the expanded string for some reason
vByteSize := vSizeNeeded + 1
If (A_PtrSize == 8) { ; Only 64-Bit builds of AHK_L will return 8, all others will be 4 or blank
vByteSize *= 2 ; need to expand to wide character sizes
}
VarSetCapacity(vTempValue, vByteSize, 0)
; attempt to expand the environment string
If (!DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Str", vTempValue, "Int", vSizeNeeded))
return False ; unable to expand the environment string
vInputString := vTempValue
; return success
Return True
}