.bat/.cmd/cmd.exe tips to speed up using windows.

You can talk about almost anything that you want to on this board.

Moderator: Moderators

User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

.bat/.cmd/cmd.exe tips to speed up using windows.

Post by FrankenGraphics »

Maybe cmd.exe is a bit out of date and i should learn powershell, but anyway. This is how i speed up work using windows (essentially by making it more comfortable to avoid the big time sink: windows explorer).

.cmd/.bat tools:

wrt.bat

Code: Select all

@echo ctrl+z = save and exit
@echo ctrl+c = just exit
@echo ======================
@echo off 
set arg1=%1
copy con %arg1%
ren *. *.txt
Functions as an in-command line text editor/replacer by (ab)using the copy command. Crude but as simple as it gets.

-In case you didn't specify a file extension, it will default to .txt.
-Good for making short config files, readmes, batch files, dummies, etc.
-It will always replace existing files, so be careful.
-Name is short for WRiTe, because w,r and t are close on the keyboard


memo.bat

Code: Select all

@echo ctrl+z = save and exit
@echo ctrl+c = just exit
@echo ======================
@echo off 
set arg1=%1
copy con %USERPROFILE%\Dropbox\memos\%arg1%
ren *. *.txt
Is a variant which automatically stores the editors' output into a designated dropbox folder so i can access it on all devices. Good for quick notation of door codes, phone numbers, grocery lists. This works so much better for me than the microsoft stickynote app because it executes directly and throws them at my phone. The memos alias (see below) helps me look at memos when i need to see them.

Hotkeying cmd.exe (and other utils)
AFAIK there's no direct hotkey to cmd. However, i've pinned it to my taskbar. All pinned programs (ranging 1-10) are accessible via the windows key. So in my case, i've got cmd on win+1, calc on win+2, notepad on win+3 and so on. That's just that little bit more convenient than accessing it indirectly via win-x or win-r to make me use it more.

Aliasing often-used folders and commands
Windows' inherent type commands for accessing certain folders are awkward. You can for example run cmd.exe, type cd %APPDATA% and hit enter. But that's too slow. Or you could hit win+r, type shell:personal, hit enter to get the document folder of the current user (what an inconsistent mess!). Regardless which way, you'd need to regedit to add custom options, afaik. Boo. Well, you can set up junctions, hardlinks, etc, but i found the following more lean and flexible:

What i use (took up this cue from stack overflow) is having one single main batch file in my dropbox folder (%USERPROFILE%\\Dropbox\\env\\main.bat to be specific)
Then, in regedit \ HKEY_CURRENT_USER \ software \ microsoft \ command processor, create a new string value:
Value: AutoStart
Data: %USERPROFILE%\\Dropbox\\env\\main.bat
Rather than keeping all my stuff in a batch folder and adding a path to the %path% variable, this makes my preferences easily portable from account to account, from computer to computer.

This is what my main.bat looks like.

Code: Select all

@echo off

:: set start folder
cd c:\

:: =====================
:: set temporary paths for quick-start programs
:: =====================
set PATH=C:\Program Files (x86)\Google\Chrome\Application\;%PATH%
set PATH=C:\Program Files (x86)\Notepad++\;%PATH%


:: ===================== 
:: quick runs
:: ===================== 
DOSKEY np=notepad $*
DOSKEY npp=notepad++ $*


:: ===================== 
:: quick lists
:: ===================== 
:: ---------------------normal, wide, page view
DOSKEY ls=dir /b $*
DOSKEY lsw=dir /w $*
DOSKEY lsp=dir /b /p $*
:: ---------------------list by date (oldest to newest)
DOSKEY lsd=dir /od $*
:: ---------------------list by extension
DOSKEY lex= dir /b /oe $*


:: ===================== 
:: filtered ls
:: ===================== 
:: ---------------------folders only
DOSKEY lsf= dir /b /ad $*
:: ---------------------non-folders only
DOSKEY lsnf= dir /b /a-d $*
:: ---------------------archives only
DOSKEY lsa= dir /b /aa $*


:: ===================== 
::sorted dirs
:: ===================== 
:: ---------------------useful for detecting 0 byte files/corrupt files; ignores folders
DOSKEY dir0= dir /a-d /o-s $*
:: ---------------------dir sorted by date (oldest to newest)
DOSKEY dird= dir /od $*


:: ===================== 
:: change directory, then auto-ls
:: ===================== 
DOSKEY cdl=%USERPROFILE%\Dropbox\env\cdl.bat $*
:: ---------------------same, but only list directories 
DOSKEY cdd=%USERPROFILE%\Dropbox\env\cdd.bat $*
:: ---------------------same, but only list files/nondirectories
DOSKEY cdnf=%USERPROFILE%\Dropbox\env\cdnf.bat $* 
:: ---------------------same, but only list archives
DOSKEY cda=%USERPROFILE%\Dropbox\env\cda.bat $


:: ===================== 
:: various bash substitutes
:: ===================== 
DOSKEY grep=findstr $*
DOSKEY diff=fc $*
DOSKEY rm=del $*


:: =====================
:: Command line text editor substitute suite
:: =====================
DOSKEY wrt=%USERPROFILE%\Dropbox\env\wrt.bat $*
DOSKEY memo=%USERPROFILE%\Dropbox\env\memo.bat $*
DOSKEY lsmem=%USERPROFILE%\Dropbox\env\lsmem.bat $*
DOSKEY mvmem=%USERPROFILE%\Dropbox\env\mvmem.bat $*
DOSKEY memos=cd %USERPROFILE%\Dropbox\memos\$*

:: =====================
:: Common directories
:: =====================
DOSKEY dropbox=cd %USERPROFILE%\Dropbox\$*
DOSKEY desktop=cd %USERPROFILE%\Desktop\$*
DOSKEY documents=cd %USERPROFILE%\Documents\$*
DOSKEY downloads=cd %USERPROFILE%\Downloads\$*
DOSKEY assembler=cd c:\cc65\$*
DOSKEY nesdev=cd %USERPROFILE%\Documents\NESDEV\$*



:: =====================
:: abbreviations of the former
:: =====================
DOSKEY cdrop=cd %USERPROFILE%\Dropbox\$*
DOSKEY cdesk=cd %USERPROFILE%\Desktop\$*
DOSKEY cdoc=cd %USERPROFILE%\Documents\$*
DOSKEY cdown=cd %USERPROFILE%\Downloads\$*
DOSKEY ccc=cd c:\cc65\$*
DOSKEY cnd=cd %USERPROFILE%\Documents\NESDEV\$*
DOSKEY cenv=cd %USERPROFILE%\Dropbox\env\$*


:: ===================== 
:: misc
:: ===================== 
:: ---------------------open current directory in win explorer
DOSKEY open=start .
:: ---------------------edit this batch file. 
DOSKEY setalias=notepad %USERPROFILE%\Dropbox\env\main.bat
:: --------------------- playground folder
DOSKEY ctest=cd %USERPROFILE%\Documents\temp\
so if i for example want to access a nesdev cc65 project, i can simply type ccc _myproject
One caveat is that this .bat runs once every time you'd start a new cmd.exe instance - but with no complex commands being made, it takes no time at all.

Other tips
Working with the cmd.exe has become much more enjoyable and quick this way. Especially with the window size hotkeys:
win+left, win-right (left and right half of screen), win+up (maximize), win+down (minimize).



What's you best tips using cmd.exe, .bat/.cmd files, etc, for making windows usage quicker/more convenient?

(edit: fixed various typos)
Last edited by FrankenGraphics on Fri Aug 25, 2017 3:40 am, edited 5 times in total.
User avatar
TmEE
Posts: 960
Joined: Wed Feb 13, 2008 9:10 am
Location: Norway (50 and 60Hz compatible :P)
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by TmEE »

I made bunch of BAT files for all the really commonly used things and placed them where the system can find them.
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by FrankenGraphics »

That's perfectly valid (and what i think most people do).

DOSKEYs will get discarded between cmd sessions, though (or rather, they are local to the instance), so if you want to use them, you need to manually run a bat for each new instance of cmd.exe, or use a blend of the two methods: All bats in a folder with a preknown path, but still make an autostart string for the one containing all DOSKEY:s.

This wouldn't have been the case in MS-DOS, of course, where you simply could drop any DOSKEYs in your startup file.
calima
Posts: 1745
Joined: Tue Oct 06, 2015 10:16 am

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by calima »

If you're going that far, why not come to the dark side?
User avatar
Dwedit
Posts: 4921
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by Dwedit »

I'm not renaming *. to *.txt any time soon, sounds dangerous.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by thefox »

Speaking of the dark side, if you're on Windows 10, "Bash on Ubuntu on Windows" gives you a fairly straightforward access to all the unixy tools. In the latest version you can even run Windows apps from the Linux subsystem (e.g., "ca65.exe blah.s" works, as long as current working directory is visible to Windows (/mnt/c/blah/...)).
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by FrankenGraphics »

dwedit wrote:I'm not renaming *. to *.txt any time soon, sounds dangerous.
No need to worry: The *. mask will let through extentionless files in the current directory so ren can rename it/them. It's a fairly commonplace procedure.

It would only be dangerous if 1) you've got extensionless files in the specific folder you've actively decided to operate in, and 2) if some software somehow relies on them being extensionless.

You can validate if you by any chance have extensionless files on your computer like so:
Windows Explorer > F3 > ext:[] type:NOT"file folder"
I didn't have a single one.

To the best of my knowledge, any extensionless file would've been user generated - there's no such system file, in any case. I don't know why anyone would want to create an extensionless file (beside making it hard to associate with a program or search for), though?

Of course, the bat could be more specific, or leave out defaulting altogether. I like to keep bats as simple as possible as to not cause weird niche quirks based on user input.

Another thing is that windows has gotten loose with its use of *. In the command line, it behaves just as it always have behaved, but in explorers' file search, it has become dilluted and lets through all files, from windows 7 and onwards (hence the more specific ext:[] when searching. This includes folders, so you need to exclude those too).
thefox wrote:if you're on Windows 10
I haven't really looked into what it'd entail moving from 8.1 to 10. But precisely the sort of thing you mentioned makes it a bit more tempting. :)
calima wrote:If you're going that far, why not come to the dark side?
Because the resistance holds Adobe and its indispensable suite in chains in the light. ;(
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by tepples »

calima wrote:If you're going that far, why not come to the dark side?
Which dark side? One that involves giving up the use of FamiTracker and FCEUX (debugging version)?
FrankenGraphics wrote:To the best of my knowledge, any extensionless file would've been user generated - there's no such system file, in any case. I don't know why anyone would want to create an extensionless file (beside making it hard to associate with a program or search for), though?
In order for a build system using GNU Make to work without specifying the -f switch every time, the user has to create a file whose name is exactly makefile, Makefile, or GNUmakefile. In addition, when a user installs an application distributed as free software, the zipfile or tarball is likely to include files with one of the following names: README, INSTALL, or COPYING.
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by FrankenGraphics »

Ah, ok. So if my computer had dual OS:es, i wouldn't want to use wrt (or rather ren *. specifically) in a folder where such a makefile exists, or else i would need to re-rename it manually afterwards. That'd be annoying.

===


Another thing i learned while writing the OP:
clip < main.bat

overwrites the windows clipboard with the contents of the text/code file. Useful for posting code without opening the file, or likewise transfer prewritten material to a blog post or the like.
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by tepples »

You're correct that a system based on POSIX, such as FreeBSD, GNU/Linux, or macOS, is more likely to have files whose names lack a full stop than a Windows system with its 8.3 heritage.

Other things that bring in some version of GNU Make include MinGW, MSYS, and Cygwin. The build process for most of my NES stuff (described in the nrom-template instructions) uses GNU Make, and it recommends that Windows users obtain it as part of MSYS.
User avatar
gauauu
Posts: 779
Joined: Sat Jan 09, 2016 9:21 pm
Location: Central Illinois, USA
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by gauauu »

tepples wrote:
calima wrote:If you're going that far, why not come to the dark side?
Which dark side? One that involves giving up the use of FamiTracker and FCEUX (debugging version)?
They work just fine with wine. No need to give them up. (Although wine makes them slightly slower and uglier)
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by tepples »

FCEUX and mainline FamiTracker work in Wine if you install 32-bit libraries, which I did but others might not. The 0CC-FamiTracker fork has several unresolved issues in Wine, some of them blockers.
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by FrankenGraphics »

In case extensions would prove a problem (for example using makefiles on windows and wanting to wrt in the same directory), this version solves it:

Code: Select all

@echo off

set arg1=%1

::checking if a temp dir exists, else makedir
if not exist %cd%\wrttemp\nul (
md wrttemp
)

::create file first in temp
pushd %cd%\wrttemp
 
@echo ctrl+z, enter to save and exit
@echo ctrl+c, terminate batch script
@echo ==================
copy con %arg1%  

::an extra dummy file avoids a nonproblematic 
::but ugly syntax error if ren finds no extensionless file to rename
copy /y nul dummy >nul
ren *. *.txt 
popd

::transfer it to current directory and clean up afterwards.
move /y %cd%\wrttemp\%arg1%.* %cd%
rd /s /q %cd%\wrttemp\
Last edited by FrankenGraphics on Fri Aug 25, 2017 3:41 am, edited 1 time in total.
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by rainwarrior »

My Windows command prompt tip:

If you hold shift while right clicking in explorer, extra options will appear in the pop-up menu, including "open command window here".
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: .bat/.cmd/cmd.exe tips to speed up using windows.

Post by FrankenGraphics »

Nice, that'll most likely come in handy!

You can also type "cmd" in the addr field of any explorer window to open it in that directory.
Post Reply