Quick tip! I often find myself in a terminal interface wanting to open a file explorer to the current folder I’m in, or finding a previous file explorer instance I opened. I recently came to a realization that made me feel silly that I didn’t think of this earlier… Like, we’re talking a decade ago kind of “earlier”.
This is written specifically for the Windows OS.
The Thing
The file explore’s executable name is explorer
, it takes in an optional command line arguments including what directory you want to open. The .
path is a special path that refers to the current working directory.
explorer .
That’s it! That line works with any and all terminal interface I use often in Windows: command line (cmd.exe), PowerShell and the MinGW used for GitBash.
Some Extra Rambling
It’s a stupid-simple optimization, but I tend to transition from terminal to file explorer a lot, and repeatedly – especially when writing automating scripts, managing files and folder hierarchies, and doing touch-ups and surgery in Git. If I’m in the terminal and want the GUI explorer for that directory, just type that in, regardless of my situation.
- I don’t need to open the file explorer by clicking on the folder button.
- I don’t check if there’s already a folder open to it, just mindlessly open another duplicate folder when needed.
- I don’t need to check the terminal’s working directory and copy it to an address bar.
- I don’t need to leave the terminal until the explorer is opened to the correct directory and my hands can remain on the keyboard.
- I don’t need to worry about what terminal client I’m in. Obviously this is meant for shell terminals, and scripting terminals won’t have this command.
It’s a small optimization, but sometimes I’m juggling so many directories and other issues and going back and fourth between terminal and the explorer and different directories, it saves time and cognitive energy. So much stuff is going on that just rereading that last sentence describing the situation gives me a headache. This may lead to creating a lot of file explorer instances, which just means closing them wholesale when there’s too many duplicates (which are easy to instantly bring back from the terminals anyways).
Cognitive effort and sanity are commodities. What you save somewhere is something that can be spent somewhere else.
– Stay strong, code on. William Leu