Yeah, let me know how it works for you. Don’t forget to play around with the code page as you do. (CP 65001 is UTF-8.)
And yeah, from the very beginning I’ve been using C and C++ from the command terminal, so it seems odd to me that so few people are familiar with it — or even reject it outright. PuTty is a whole lot of overhead to not use my machine directly.
I suppose I ought to finish my Windows Command-Line How-To FAQ. It really isn’t very hard. The key is:
Control Your PATH
That’s it!
Of course, there is a little more to it than that.
I keep a little directory under my account:
C:\Users\Michael\bin.
In that directory I keep a file called
prompt.bat, which is more or less equivalent to a
.profile or
.bashrc file in *nix. Here is the current content:
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
|
@echo off
cls
path C:\Users\Michael\bin;%PATH%
set DIRCMD=/ogn
:: Macro Aliases
doskey deltree=rd/s/q $*
doskey dira=dir/a $*
doskey dird=dir/a-hd $*
doskey mcd=@md $* $T @cd $*
doskey mpath=for %%A in ("%%PATH:;=";"%%") do @if not "%%~A"=="" @echo %%~A
doskey rmq=del *.~*
doskey 7z="C:\Program Files (x86)\7-Zip\7z.exe" $*
doskey astyle=C:\m\bin\AStyle\bin\astyle.exe -A1 -s2 $*
doskey cppdocs=start "" C:\Users\Michael\Documents\Programming\cpp.reference.com\reference\en\index.html
doskey gimp="C:\Program Files\GIMP 2\bin\gimp-2.10.exe" $*
doskey hxd="C:\Program Files (x86)\HxD\HxD.exe" $*
doskey md5=CertUtil -hashfile $1 MD5
doskey npp="C:\Program Files (x86)\Notepad++\Notepad++" $*
doskey sdx=tclsh C:\Users\Michael\bin\sdx.kit $*
doskey sha256=CertUtil -hashfile $1 SHA256
doskey tcldocs=start "" /max C:\Users\Michael\Documents\Programming\TclTk86.chm
|
Inside my little “bin” directory, in addition to programs like
less.exe and
grep.exe (GNU Tools), inside this directory I also have a number of little batch files to manipulate the environment. For example:
markdown_edit.bat:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
@echo off
setlocal
for %%A in ("%%PATH:;=";"%%") do if %%A == C:\Python37 goto :PYOK
path C:\Python37\Scripts;C:\Python37;%PATH%
:PYOK
if "%1"=="" (
set F=README.md
) else (
set F="%~f1"
)
if not exist %F% echo #title > %F%
start "" markdown_edit %F%
|
This particular one is a little messy, but straight-forward. Add Python 3.7 to the path temporarily (but only if it isn’t already in the path*) and start
Mike Ward’s Markdown Edit python script without disrupting my use of the existing prompt. (Just like starting any other normal GUI program.)
* This is because I keep my path very clean. If a utility is not in use, it isn’t in my path. I will explain raisins in just a moment.
Another example is
python.bat, which simply adds Python 3 and the scripts directory to the head of the path and activates the python interpreter with the arguments I provided.
python.bat:
1 2 3
|
@echo off
path C:\Python37\Scripts;C:\Python37;%PATH%
python.exe %*
|
This kind of thinking allows transparent path management at the prompt. I can type “
python quux.py” at any time and it will work properly, bringing the entire Python 3.7 environment to instant use.
When I am done with Python, I can either restart the prompt or use another little utility to remove it. What I have is actually fairly complex, but a line like the following would do:
|
@path %PATH:C:\Python37\Scripts;C:\Python37;=%
|
For C++ compilers that do
a lot of PATH modification (like MSVC), I also tend to nest a call to
cmd.exe, so that I can start and use the compiler and then remove it by simply typing “
exit”.
Path manipulation matters.
On Windows, especially, this is important because there may otherwise be more than one version of a tool sitting around in your path, and mixing stuff results in Bad Things Happening
TM.
For example, you may have a variant copy of MinGW sitting around from each of MSYS2, Code::Blocks, Strawberry Perl, TDM-MinGW-w64, plus other random stuff. Each version is incompatible, and utilities that come with each version may or may not choose to run the version you
think you are using or some version you
don’t think you are running.
Set your Windows Console Properties Defaults
I keep a shortcut on my TaskBar for the Windows Console. From that I have modified the Windows Console Properties to make it use the proper font (Lucida Console Unicode) and position itself nicely on the screen, and have a much larger space than the tiny 80 by 25 default.
I can tell a properly-initialized console from something the system or another program generates easily enough, but you could just modify the global Windows Console Properties so that
all consoles start in a way you like as well.
ConEmu
For the last couple of years I have been using
Maximus5’s ConEmu as my main terminal when programming. Setting it up to work much like the Windows Console is easy, and it does a few things to make life a whole lot easier as well. But that is a blog for another day, LOL.
I have yet to play with Microsoft’s latest Windows Terminal (or whatever it is called), and I can’t stand the PowerShell, so...
That’s all folks!