<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: Улучшение cmd.exe]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11436&amp;type=atom" />
	<updated>2016-05-20T11:20:15Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11436</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Улучшение cmd.exe]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=103983#p103983" />
			<content type="html"><![CDATA[<p>Выполнение команд в одной строке<br /></p><div class="codebox"><pre><code>@echo off
setlocal enabledelayedexpansion
Call :parse &quot;1 #add; factorial(6) #sub; 1&quot;
endlocal
exit /b

:parse
setlocal
set erft[1]=Syntax error, check for parenthesys allocation
set erfc[1]=Error #1 : Bracket friend has not been detected &quot;(&quot;

set erft[2]=Syntax error, check for parenthesys allocation
set erfc[2]=Error #2 : Undeclared end &quot;)&quot;

set erft[3]=Syntax error, check for functions
set erfc[3]=Error #3 : Undefined &quot;;&quot;

set erft[4]=Syntax error, check for functions
set erfc[4]=Error #4 : Undefined &quot;#&quot;

set erft[5]=Syntax error, check for functions
set erfc[5]=Error #5 : In &quot;#&quot; and &quot;;&quot; is not allowed to place spaces and brackets

set erft[6]=Syntax error, check for functions
set erfc[6]=Error #6 : Missing last argument

set output=%2
set t=%~1
Call :getsize &quot;!t!&quot; a
set /a b=a - 1
rem Check for syntax correct
set par=0
set err=0
set errpos=
set stat=0
for /l %%i in (0,1,!b!) do (
	if not &quot;!t:~%%i,1!&quot;==&quot; &quot; if !stat!==2 set stat=0
	if &quot;!t:~%%i,1!&quot;==&quot;(&quot; set /a par+=1
	if &quot;!t:~%%i,1!&quot;==&quot;)&quot; set /a par-=1
	if &quot;!t:~%%i,1!&quot;==&quot;#&quot; set stat=1
	if &quot;!t:~%%i,1!&quot;==&quot; &quot; if !stat!==1 set err=5&amp;set errpos=%%i
	if &quot;!t:~%%i,1!&quot;==&quot;(&quot; if !stat!==1 set err=5&amp;set errpos=%%i
	if &quot;!t:~%%i,1!&quot;==&quot;)&quot; if !stat!==1 set err=5&amp;set errpos=%%i
	if &quot;!t:~%%i,1!&quot;==&quot;;&quot; (
		if !stat!==1 (
			set stat=2
		) else (
			set err=4
			set errpos=%%i
		)
	)
	if !par! lss 0 set err=1&amp;set errpos=%%i
)
if !par! gtr 0 set err=2
if !stat!==1 set err=3
if !stat!==2 set err=6
rem Fall with error
if !err! neq 0 (
	if defined errpos Echo Syntax error at : !errpos!
	Echo !erft[%err%]!
	Echo !erfc[%err%]!
	goto :eof
)
rem Parse First Brackets
if not &quot;!t!&quot;==&quot;!t:(=!&quot; (
	rem Get last and first brackets
	rem Echo DEBUG: &quot;!t!&quot;
	rem Find first closing symbol
	set opengate=0
	set opengatepos=
	for /l %%i in (0,1,!b!) do (
		if !opengate!==0 (
			if &quot;!t:~%%i,1!&quot;==&quot;)&quot; set opengate=1&amp;set opengatepos=%%i
		)
	)
	rem Echo !opengatepos!
	rem Find first opening symbol
	set closegate=0
	set closegatepos=
	for /l %%i in (!opengatepos!,-1,0) do (
		if !closegate!==0 (
			if &quot;!t:~%%i,1!&quot;==&quot;(&quot; set closegate=1&amp;set closegatepos=%%i
		)
	)
	rem Echo !closegatepos!
	rem Distance beetwen close and open brackets
	set /a &quot;abs=opengatepos-closegatepos-1&quot;
	rem Us 007
	set /a &quot;tmp001=closegatepos + 1&quot;
	set /a &quot;tmp003=opengatepos+1&quot;
	set /a &quot;tmp006=closegatepos-1&quot;
	rem Echo !abs!
	rem wordname detector
	if !closegatepos!==0 (
		rem [SOF] &quot;(&quot; exp &quot;)&quot;
		Call :substr t !tmp001! !abs! tmp002
		rem Echo DEBUG:  !tmp002!
		Call :substr t !tmp003! -1 tmp004
		Call :parse &quot;!tmp002!&quot; result
		rem Echo !tmp004!
	) else (
		rem ??? but not [SOF] &quot;(&quot; exp &quot;)&quot;
		rem [function name] without &#039;#&#039; and &#039;;&#039; &quot;(&quot; exp &quot;)&quot;
		rem [brackets] with &#039;#&#039; and &#039;;&#039; &quot;(&quot; exp &quot;)&quot;
		set nameoffunc=
		set parsefuncname=0
		set w=0
		for /l %%i in (!tmp006!,-1,0) do (
			if !parsefuncname!==0 (
				if &quot;!t:~%%i,1!&quot;==&quot;(&quot; set parsefuncname=1
				if &quot;!t:~%%i,1!&quot;==&quot;)&quot; set parsefuncname=1
				if &quot;!t:~%%i,1!&quot;==&quot; &quot; set parsefuncname=1
				if &quot;!t:~%%i,1!&quot;==&quot;;&quot; set parsefuncname=1
				if !parsefuncname!==0 (
					set nameoffunc=!t:~%%i,1!!nameoffunc!
					set w=%%i
				)
			)
		)
		if defined nameoffunc (
			if !abs!==0 (
				rem ???
			) else (
				Call :substr t !tmp001! !abs! tmp007
				Call :parser-!nameoffunc! result !tmp007!
				rem Echo DEBUG:  &#039;!tmp007!&#039;
				Call :substr t 0 !w! tmp008
				Call :substr t !tmp003! 9999 tmp009
				Call :parse &quot;!tmp008!!result!!tmp009!&quot;
				rem Echo DEBUG:  &#039;!tmp008!&#039;!result!&#039;!tmp009!&#039;
			)
		) else (
			rem ???
		)
	)
	
) else if not &quot;!t!&quot;==&quot;!t:#=!&quot; (
	set state=0
	set arga=
	set argb=
	set nameoffunc=
	for /l %%i in (0,1,!b!) do (
		if !state!==0 if &quot;!t:~%%i,1!&quot;==&quot;#&quot; set state=1&amp;set topos1=%%i
		if !state!==1 if &quot;!t:~%%i,1!&quot;==&quot;;&quot; set state=2&amp;set topos2=%%i
		if !state!==2 if &quot;!t:~%%i,1!&quot;==&quot;#&quot; set state=3&amp;set topos3=%%i
		if !state! leq 2 (
			if not &quot;!t:~%%i,1!&quot;==&quot; &quot; (
			if !state!==0 set arga=!arga!!t:~%%i,1!
			if not &quot;!t:~%%i,1!&quot;==&quot;;&quot; if !state!==2 set argb=!argb!!t:~%%i,1!
			if not &quot;!t:~%%i,1!&quot;==&quot;#&quot; if !state!==1 set nameoffunc=!nameoffunc!!t:~%%i,1!
			)
		)
	)
	Call :substr t !topos3! 9999 tast
	Call :parser-!nameoffunc! return !arga! !argb!
	Call :parse &quot;!return!!tast!&quot;
) else (
	Echo Result : !t!
)
endlocal
goto :eof

:substr
set %4=!%1:~%2,%3!
goto :eof

:getsize
setlocal enabledelayedexpansion
set min=0&amp;set max=8192
set text=%~1
if &quot;!text!&quot;==&quot;&quot; set size=0&amp;goto getsize_end
	:getsize_loop
	set /a am=(min+max) / 2
	set /a amp=am + 1
	if &quot;!text:~%am%,1!&quot;==&quot;&quot; set max=!am!&amp;goto getsize_loop
	if not &quot;!text:~%amp%,1!&quot;==&quot;&quot; set min=!am!&amp;goto getsize_loop
	set size=!am!
set /a size+=1
:getsize_end
endlocal&amp;set %2=%size%
goto :eof

:parser-factorial
set %1=1
for /l %%i in (1,1,%2) do (
	set /a %1*=%%i
)
goto :eof

:parser-add
set /a %1=%2+%3
goto :eof

:parser-sub
set /a %1=%2-%3
goto :eof

:parser-mul
set /a %1=%2*%3
goto :eof

:parser-div
set /a %1=%2/%3
goto :eof
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[torus]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33003</uri>
			</author>
			<updated>2016-05-20T11:20:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=103983#p103983</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[CMD/BAT: Улучшение cmd.exe]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=101981#p101981" />
			<content type="html"><![CDATA[<p><strong>Предисловие</strong></p><p>Разрабатывая этот скрипт setcmd.bat,&nbsp; я получил удовольствие. Хотя сам его не использую в повседневной жизни, отдавая предпочтение сторонним, более продвинутым средствам, таким как Clink, ConEmu, Far. Тем не менее считаю, что этот велосипед можно использовать. </p><br /><p><strong>Описание</strong></p><p>Этот скрипт позиционируется как расширение возможностей стандартного cmd.exe, попытка сделать его чуть ближе к родственным оболочкам, например, таким как bash. </p><br /><p><strong>Алиасы, макрокоманды</strong></p><p>Аналог команды doskey, но синтаксисом попроще и чуть гибче. </p><p><strong>alias</strong><br />показать все алиасы</p><p><strong>alias name=text</strong><br />определить новый алиас</p><p><strong>alias -r [ FILENAME ]</strong><br />загрузить новый список алиасов из указанного файлы FILENAME. Если файл не задан, то пытается загрузить из файла, заданного переменной %CMD_ALIASFILE%. </p><p><strong>unalias</strong><br />удалить алиас</p><br /><p><strong>История команд</strong></p><p>История команд в cmd.exe не ведется совсем. Это попытка хоть как-то улучшить положение. Команды предыдущей сессии загрузить нельзя, но можно их хотя бы сохранить. </p><p><strong>history</strong><br />показать историю команд текущей сессии</p><p><strong>history -c</strong><br />очистить историю команд в текущей сессии</p><p><strong>history -w</strong><br />сохранить (дописать) текущую сессию в заданный файл. Имя файла задается переменной %CMD_HISTFILE%. Размер истории можно задать с помощью следующих переменных %CMD_HISTSIZE% - максимальное количество команд хранимых в буфере текущей сессии (по умолчанию 50). %CMD_HISTFILESIZE% - количество строк, которые можно хранить в файле истории (более старые удаляются при превышении этого значения, Если %CMD_HISTFILE% или %CMD_HISTFILESIZE% не заданы, то история не сохраняется. </p><br /><p><strong>Навигация</strong></p><p><strong>cd</strong><br />показать текущий каталог</p><p>В bash эта команда вернется в домашний каталог пользователя, но я решщил оставить стандартное поведение встроенной команды cmd.exe. </p><p><strong>cd -</strong><br />перейти в предыдущий каталог. </p><p><strong>cd ~</strong><br />перейти в домашний каталог пользователя %USERPROFILE%</p><p><strong>cd path</strong><br />перейти в заданный каталог</p><p><strong>Завершение сессии</strong></p><p>По завершении сессии история команд сбрасывается (дописывается) в файл истории. Для этого определены следующие алиасы</p><p><strong>exit</strong><br /><strong>CTRL-D</strong></p><p>Последний алиас это символ <strong>CTRL-D</strong>, <strong>ASCII 04</strong>, обычно отображаемый как <strong>^D</strong>. В отличие от unix-овых оболочек, которые автоматически завершают сессию и закрывают тенрминал здесь требуется подтвердить нажатием клавиши <strong>enter</strong>. </p><br /><p><strong>Конфигурирование</strong></p><p>Изменить поведение скрипта можно с помощью пользовательского скрипта setcmd.rc.bat, который может быть загружен из </p><p>а) каталога %CMD_SETCMDDIR%, где установлен скрипт setcmd.bat, <br />б) каталога %HOME% (если задан), <br />в) каталога пользователя %USERPROFILE%. </p><p><strong>CMD_ALIASFILE</strong><br />имя файла алиасов</p><p><strong>CMD_ALIAS_NOBUILTINS</strong><br />непустое значение запрещает установку встроенных алиасов (смотри список выше)</p><p><strong>CMD_HISTFILE</strong><br />имя файла истории для сохранения текущей сессии</p><p><strong>CMD_HISTFILESIZE</strong><br />предельное количество строк в файле истории</p><p><strong>CMD_HISTSIZE</strong><br />предельное количество строк в истории текущей сессии</p><br /><p><strong>Автозапуск</strong></p><p>Можно настроить так, что этот скрипт будет автоматически выполнятся при каждом запуске cmd.exe</p><p><strong>setcmd autorun -i</strong><br />инсталлировать автозапуск скрипта</p><p><strong>setcmd autorun -u</strong><br />деинсталлировать завтозапуск скрипта</p><br /><p><strong>Исходный код</strong></p><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;исходный код setcmd.bat</div><div class="fancy_spoiler"><p>Оригинал скрипта и самая его свежая версия находится по адресу: <br /><a href="https://github.com/ildar-shaimordanov/cmd.scripts/blob/master/setcmd.bat">https://github.com/ildar-shaimordanov/c … setcmd.bat</a></p><div class="codebox"><pre><code>
::
:: The tool was developed to enhance the functionality of `cmd.exe` 
:: similar to Unix-like shells. It is completely written as batch script 
:: and does npt add any external binaries. Nevertheless, it gives more 
:: functions and flexibility to `cmd.exe` and do maintainance little bit 
:: easier. 
::
:: In fact, this script is weak attempt to be closer to other shells - 
:: powerful, flexible and full-functional ones. Nevertheless, it works! 
:: This script can be found useful for those folks, who are not permitted 
:: to setup any other binaries excepting those applications permitted for 
:: installation. The better way is to use the other solutions like 
:: `Clink`, `ConEmu` or something else. 
::
@echo off

for %%1 in (

	&quot;help&quot;
	&quot;alias.readfile&quot;
	&quot;history&quot;
	&quot;cd&quot;
	&quot;autorun&quot;

) do if /i &quot;%~1&quot; == &quot;%%~1&quot; (
	call :cmd.%*
	goto :EOF
)

if not &quot;%~1&quot; == &quot;&quot; (
	&gt;&amp;2 echo:Unknown command &quot;%~1&quot;.
	goto :EOF
)


::
:: # USER DEFINED FILE
::
::
:: The user defined file `setcmd.rc.bat` allows to customize the user&#039;s 
:: environment. Firstly, it is checked for existance in the same directory 
:: where `setcmd.bat` is located, further it is checked under the `HOME` 
:: directory and finally under the user&#039;s profile. If these files exist 
:: they are called and affects on the further execution. Each of them can 
:: override previous settings. 
::
:: This behavior is very close to the existing in unix world when settings 
:: of `~/.bashrc` override settings of `/etc/bashrc`. 
::
:: The `CMD_SETCMDDIR` environment variable points to the directory where 
:: the main script `setcmd.bat` is located. It can be used, if some 
:: settings are placed under this directory. 
::
for /f &quot;tokens=*&quot; %%f in ( &quot;%~dp0.&quot; ) do set &quot;CMD_SETCMDDIR=%%~ff&quot;

if exist &quot;%~dpn0.rc.bat&quot; call &quot;%~dpn0.rc.bat&quot;
if exist &quot;%HOME%\%~n0.rc.bat&quot; call &quot;%HOME%\%~n0.rc.bat&quot;
if exist &quot;%USERPROFILE%\%~n0.rc.bat&quot; call &quot;%USERPROFILE%\%~n0.rc.bat&quot;


::
:: # ENVIRONMENT VARIABLES
::
::
:: Behaviour of the script depends on some environment variables described 
:: below. Most of them have synonyms in unix and the same meaning. 
::
:: Uncomment a line if you want to turn on a feature supported by a 
:: variable. The better place for tuning all these variables is auxiliary 
:: `setcmd.rc.bat` script (see the description above). 
::
::
:: `CMD_ALIASFILE`
::
:: Define the name of the file of aliases or `DOSKEY` macros. 
::
if not defined CMD_ALIASFILE set &quot;CMD_ALIASFILE=%~dpn0.aliases&quot;
::
:: `CMD_ALIAS_NOBUILTINS`
::
:: Any non-empty value disables setting of builtin aliases at startup. 
::
rem if not defined CMD_ALIAS_NOBUILTINS set &quot;CMD_ALIAS_NOBUILTINS=1&quot;
::
:: `CMD_HISTFILE`
::
:: Define the name of the file in which command history is saved. 
::
rem if not defined CMD_HISTFILE set &quot;CMD_HISTFILE=%~dpn0.history&quot;
::
:: `CMD_HISTFILESIZE`
::
:: Define the maximum number of lines in the history file. 
::
rem if not defined CMD_HISTFILESIZE set /a &quot;CMD_HISTFILESIZE=500&quot;
::
:: `CMD_HISTSIZE`
::
:: Define the maximum number of commands remembered by the buffer. 
:: By default `DOSKEY` stores `50` latest commands in its buffer. 
::
rem if not defined CMD_HISTSIZE set /a &quot;CMD_HISTSIZE=50&quot;
::
:: `CMD_HISTCONTROL`
::
:: A semicolon-separated list of values controlling how commands are saved 
:: in the history file. 
::
:: **Not implemented**
::
rem if not defined CMD_HISTCONTROL set &quot;CMD_HISTCONTROL=&quot;
::
:: `CMD_HISTIGNORE`
::
:: A semicolon-separated list of ignore patterns used to decide which 
:: command lines should be saved in the history file. 
::
:: **Not implemented**
::
rem if not defined CMD_HISTIGNORE set &quot;CMD_HISTIGNORE=&quot;

if not defined CMD_ALIAS_NOBUILTINS call :cmd.alias.builtins
if exist &quot;%CMD_ALIASFILE%&quot; call :cmd.alias.readfile &quot;%CMD_ALIASFILE%&quot;

goto :EOF


:cmd.help
for /f &quot;tokens=* delims=: &quot; %%s in ( &#039; 
	findstr /b &quot;::&quot; &quot;%~f0&quot; 
&#039; ) do echo:%%~s
goto :EOF


:cmd.alias.builtins
::
:: # ALIASES
::
::
:: `alias`
::
:: Display all aliases.
::
::
:: `alias name=text`
::
:: Define an alias with the name for one or more commands.
::
::
:: `alias -r [FILENAME]`
::
:: Read aliases from the specified file or `CMD_ALIASFILE`.
::
doskey alias=^
if &quot;$1&quot; == &quot;&quot; ( doskey /macros ) else ^
if &quot;$1&quot; == &quot;-r&quot; ( &quot;%~f0&quot; alias.readfile &quot;$2&quot; ) else ( doskey $* )
::
:: `unalias name`
::
:: Remove the alias specified by name from the list of defined aliases.
:: Run `DOSKEY /?` for more details.
::
doskey unalias=doskey $1=
::
:: `history`
::
:: Display or manipulate the history list for the actual session. 
:: Run `DOSKEY /?` for more details.
::
doskey history=&quot;%~f0&quot; history $1
::
:: `cd`
::
:: Display or change working directory. 
::
doskey cd=&quot;%~f0&quot; cd $1
::
:: `exit`
::
:: Exit the current command prompt; before exiting store the actual 
:: history list to the history file `CMD_HISTFILE` when it is configured. 
::
doskey exit=if not &quot;$1&quot; == &quot;/?&quot; ( &quot;%~f0&quot; history -w ) $T exit $*
::
:: `CTRL-D`
::
:: `CTRL-D` (`ASCII 04`, `EOT` or the *diamond* symbol) is useful shortcut 
:: for the `exit` command. Unlike Unix shells the `CTRL-D` keystroke 
:: doesn&#039;t close window immediately. In Windows command prompt you need to 
:: press the `ENTER` keystroke. 
::
doskey =&quot;%~f0&quot; history -w $T exit
goto :EOF


::
:: # ALIAS FILE
::
::
:: Alias file is the simple text file defining aliases or macros in the 
:: form `name=command` and can be loaded to the session by the prefedined 
:: alias `alias -r`.
::
:cmd.alias.readfile
setlocal

if not &quot;%~1&quot; == &quot;&quot; set &quot;CMD_ALIASFILE=%~1&quot;

if not defined CMD_ALIASFILE (
	endlocal
	goto :EOF
)

if not exist &quot;%CMD_ALIASFILE%&quot; (
	&gt;&amp;2 echo:&quot;%CMD_ALIASFILE%&quot; not found.
	endlocal
	goto :EOF
)

set /a &quot;CMD_HISTSIZE=CMD_HISTSIZE&quot;
if %CMD_HISTSIZE% gtr 0 doskey /LISTSIZE=&quot;%CMD_HISTSIZE%&quot;

doskey /MACROFILE=&quot;%CMD_ALIASFILE%&quot;

endlocal
goto :EOF


::
:: # HISTORY
::
::
:: `history [options]`
::
::
:: ## Options
::
:cmd.history
if &quot;%~1&quot; == &quot;&quot;   goto :cmd.history.print
if &quot;%~1&quot; == &quot;-c&quot; goto :cmd.history.clear
if &quot;%~1&quot; == &quot;-C&quot; goto :cmd.history.uninstall
if &quot;%~1&quot; == &quot;-w&quot; goto :cmd.history.write

&gt;&amp;2 echo:Unsupported history option &quot;%~1&quot;.
goto :EOF


::
:: `history`
::
:: Displays the history of the current session.
::
:cmd.history.print
doskey /HISTORY
goto :EOF


::
:: `history -c`
::
:: Clear the history list by setting the history size to 0 and reverting 
:: to the value defined in `CMD_HISTSIZE` or `50`, the default value. 
::
:cmd.history.clear
setlocal

set /a &quot;CMD_HISTSIZE=CMD_HISTSIZE&quot;
if %CMD_HISTSIZE% leq 0 set CMD_HISTSIZE=50
doskey /LISTSIZE=0
doskey /LISTSIZE=%CMD_HISTSIZE%

endlocal
goto :EOF


::
:: `history -C`
::
:: Install a new copy of `DOSKEY` and clear the history buffer. This way 
:: is less reliable and deprecated in usage because of possible loss of 
:: control over the command history. 
::
:cmd.history.uninstall
doskey /REINSTALL
goto :EOF


::
:: `history -w`
::
:: Write the current history to the file `CMD_HISTFILE` if it is defined. 
::
:cmd.history.write
if not defined CMD_HISTFILE goto :EOF

doskey /HISTORY &gt;&gt;&quot;%CMD_HISTFILE%&quot; || goto :EOF

if not defined CMD_HISTFILESIZE goto :EOF

setlocal 

set /a &quot;CMD_HISTFILESIZE=CMD_HISTFILESIZE&quot;
set /a &quot;CMD_FILEPOS=0&quot;

for /f %%f in ( &#039; 
	&quot;%windir%\System32\more.exe&quot; ^&lt; &quot;%CMD_HISTFILE%&quot; ^| ^
	&quot;%windir%\System32\find.exe&quot; /v /c &quot;&quot; 
&#039; ) do (
	set /a &quot;CMD_FILEPOS=%%f-CMD_HISTFILESIZE&quot;
)

if %CMD_FILEPOS% leq 0 (
	endlocal
	goto :EOF
)

more +%CMD_FILEPOS% &quot;%CMD_HISTFILE%&quot; &gt;&quot;%CMD_HISTFILE%~&quot;
move /y &quot;%CMD_HISTFILE%~&quot; &quot;%CMD_HISTFILE%&quot;

endlocal
goto :EOF


::
:: # CHANGE DIRECTORY
::
::
:: `cd [options]`
::
::
:: Change the current directory can be performed by the following commands 
:: `CD` or `CHDIR`. To change both current directory and drive the option 
:: `/D` is required. To avoid certain typing of the option and simplify 
:: navigation between the current directory, previous one and user&#039;s home 
:: directory, the command is extended as follows.
::
:: See the following links for details
::
:: * http://ss64.com/nt/pushd.html
:: * http://ss64.com/nt/popd.html
:: * http://ss64.com/nt/cd.html
::
:: There is another way how to combine `cd`, `pushd` and `popd`. You can 
:: find it following by the link:
::
:: * https://www.safaribooksonline.com/library/view/learning-the-bash/1565923472/ch04s05.html
::
::
:: `cd`
::
:: Display the current drive and directory.
::
::
:: `cd ~`
::
:: Change to the user&#039;s home directory.
::
::
:: `cd -`
::
:: Change to the previous directory. The previously visited directory is 
:: stored in the OLDCD variable. If the variable is not defined, no action 
:: happens. 
::
::
:: `cd path`
::
:: Change to the directory cpecified by the parameter.
::
:cmd.cd
if &quot;%~1&quot; == &quot;-&quot; if not defined OLDCD (
	&gt;&amp;2 echo:OLDCD not set
	goto :EOF
)

if &quot;%~1&quot; == &quot;&quot; (
	cd
	goto :EOF
)

setlocal

if &quot;%~1&quot; == &quot;-&quot; (
	set &quot;NEWCD=%OLDCD%&quot;
) else if &quot;%~1&quot; == &quot;~&quot; (
	set &quot;NEWCD=%USERPROFILE%&quot;
) else (
	set &quot;NEWCD=%~1&quot;
)

endlocal &amp; set &quot;OLDCD=%CD%&quot; &amp; cd /d &quot;%NEWCD%&quot;
goto :EOF


:cmd.autorun
setlocal

set &quot;CMD_AUTORUN=HKCU\Software\Microsoft\Command Processor&quot;

if &quot;%~1&quot; == &quot;-s&quot; (
	reg query  &quot;%CMD_AUTORUN%&quot; /v &quot;AutoRun&quot;
) else if &quot;%~1&quot; == &quot;-i&quot; (
	reg add    &quot;%CMD_AUTORUN%&quot; /v &quot;AutoRun&quot; /t REG_EXPAND_SZ /d &quot;\&quot;%~f0\&quot;&quot; /f
) else if &quot;%~1&quot; == &quot;-u&quot; (
	reg delete &quot;%CMD_AUTORUN%&quot; /v &quot;AutoRun&quot; /f
) else (
	&gt;&amp;2 echo:Unsupported autorun option &quot;%~1&quot;.
)

endlocal
goto :EOF


::
:: # ADDITIONAL REFERENCES
::
:: * https://msdn.microsoft.com/ru-ru/library/windows/desktop/ee872121%28v=vs.85%29.aspx
:: * http://www.outsidethebox.ms/12669/
:: * http://www.transl-gunsmoker.ru/2010/09/11.html
:: * http://habrahabr.ru/post/263105/
::
</code></pre></div></div></div>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2016-03-23T23:16:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=101981#p101981</id>
		</entry>
</feed>
