Easy way to command prompt at current folder

Talk about anything
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Easy way to command prompt at current folder

03 Jan 2015, 21:21

I have a hotkey to open up a command prompt for the active window. Since I use git quite a bit, it opens a git shell instead of cmd if it finds a git repository. But sometimes I don't want a git shell; I want cmd.exe.

So after typing win+r, cmd, enter and cd'ing to the copy-pasted path several times in one day, I had a random idea: in the address bar, prefix the current path with cmd /k cd and hit enter. It worked. Somehow that seemed easier.

The second time around, I got a message "The directory name is invalid." What was even more odd was that the command prompt was at the right directory anyway. So I realized that I didn't even need the directory; when you type a command in the address bar, it uses the working directory of the folder you're looking at. So:

Press Alt+D, type cmd and press Enter.

I can't believe I never thought of that before. Now, I could make a hotkey to open cmd.exe, but it's still useful to know. (But Alt+D probably depends on the OS language.)

Later, I realized the reason for the error: when you run an exe from the address bar in Windows 7, the address bar's content changes to the full path of the exe. :headwall:
User avatar
joedf
Posts: 7285
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Easy way to command prompt at current folder

04 Jan 2015, 01:56

Ill have to try that!
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
garry
Posts: 1885
Joined: 22 Dec 2013, 12:50

Re: Easy way to command prompt at current folder

05 Jan 2015, 15:32

this I used (XP) to open cmd

Code: Select all

 ;-- DOSCOMMANDHERE XP ctrl+alt+d :
 ^!d::
 ID := WinExist("A")
 WinGetClass, Class, ahk_id %ID%
 ControlGetText,ePath, Edit1, ahk_id %ID%
 if epath=
    epath=%A_desktop%
 Run, %comspec%, %epath%
return
Morpheus
Posts: 119
Joined: 04 Oct 2013, 05:09

Re: Easy way to command prompt at current folder

05 Jan 2015, 16:00

You can also drag and drop a folder onto the command prompt to enter the path.
User avatar
joedf
Posts: 7285
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: Easy way to command prompt at current folder

05 Jan 2015, 16:00

Nice!
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 4.00 GHz, 2x8GB G.Skill RipJaws V - DDR4 3280 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
User avatar
tidbit
Posts: 1147
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Easy way to command prompt at current folder

06 Jan 2015, 15:53

or shift+right click the parent folder:
http://i.imgur.com/UtK24WY.gif
Image
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Easy way to command prompt at current folder

06 Jan 2015, 16:51

I'm usually in the folder I want to open. You can right click in empty space instead of on a folder item, but that requires having one hand on the mouse...
tmplinshi
Posts: 1520
Joined: 01 Oct 2013, 14:57

Re: Easy way to command prompt at current folder

07 Jan 2015, 02:50

garry wrote:this I used (XP) to open cmd

Code: Select all

 ;-- DOSCOMMANDHERE XP ctrl+alt+d :
 ^!d::
 ID := WinExist("A")
 WinGetClass, Class, ahk_id %ID%
 ControlGetText,ePath, Edit1, ahk_id %ID%
 if epath=
    epath=%A_desktop%
 Run, %comspec%, %epath%
return
Unfortunately, this doesn't work in WIN7.

Now I'm using this one:

Code: Select all

#c::cmdHere()
 
cmdHere() {
	If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass") {
		WinHWND := WinActive()
		For win in ComObjCreate("Shell.Application").Windows
			If (win.HWND = WinHWND) {
				dir := SubStr(win.LocationURL, 9) ; remove "file:///"
				dir := RegExReplace(dir, "%20", " ")
				Break
			}
	}
	Run, cmd, % dir ? dir : A_Desktop
}
tmplinshi
Posts: 1520
Joined: 01 Oct 2013, 14:57

Re: Easy way to command prompt at current folder

07 Jan 2015, 03:27

Code: Select all

#c::cmdHere()

cmdHere() {
	If WinActive("ahk_class CabinetWClass") || WinActive("ahk_class ExploreWClass")
		WinGetText, data
	Run, cmd, % RegExMatch(data, "i`am)^Address: \K.*", dir) ? dir : A_Desktop
	; You'll need to change the word "Address" to your os language.
}
Found the idea from http://www.autohotkey.com/board/topic/5 ... /?p=432380.
guest3456
Posts: 2656
Joined: 09 Oct 2013, 10:31

Re: Easy way to command prompt at current folder

08 Jan 2015, 01:02

lexikos wrote: So I realized that I didn't even need the directory; when you type a command in the address bar, it uses the working directory of the folder you're looking at. So:

Press Alt+D, type cmd and press Enter.
awesome thanks
lexikos wrote:I'm usually in the folder I want to open. You can right click in empty space instead of on a folder item, but that requires having one hand on the mouse...
if you're using Folders, don't you usually already have a hand on the mouse? usually people using only the shell are the ones complaining about mouse usage

lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Easy way to command prompt at current folder

08 Jan 2015, 01:34

No, I use the keyboard more often. In this particular case I was alt-tabbing to the folder just to get the path, because I kept the folder open but not the command prompts.

Return to “Offtopic”

Who is online

Users browsing this forum: JohnyWalter and 26 guests