Easy way to command prompt at current folder

Talk about anything
lexikos
Posts: 9569
Joined: 30 Sep 2013, 04:07
Contact:

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:
garry
Posts: 3746
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
tidbit
Posts: 1272
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: 9569
Joined: 30 Sep 2013, 04:07
Contact:

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: 1604
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: 1604
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: 3454
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: 9569
Joined: 30 Sep 2013, 04:07
Contact:

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 “Off-topic Discussion”

Who is online

Users browsing this forum: No registered users and 30 guests