Cmd text box functionality for Git

Asked

Viewed 291 times

5

I’m developing a .bat, which will make a series of commands from the git predefined. But one of these commands, it is necessary that the user type an operation message.

Follow the series of commands:

cd C:\xampp\htdocs\laravelapi
set filedatetime=%date% // ou qualquer outra data
set filedatetime=%filedatetime:~0,2%%filedatetime:~3,2%%filedatetime:~6,4%
git add .
git commit -m "Novo versionamento %filedatetime%%username%"
git push

There’s some way to make that by executing the .bat, it opens a text box on the screen for the user to type the message and so save in a variable before the git commit -m "Novo versionamento %filedatetime%%username%"?

I’m using Windows 10 Home.

2 answers

11


You can use the set /p to request the entry of information and associate to a variable.

The syntax is: set /p nome_da_variavel="Texto de solicitação: "

In its code, it would be the equivalent of:

@echo off

cd C:\xampp\htdocs\laravelapi
set filedatetime=%date% // ou qualquer outra data
set filedatetime=%filedatetime:~0,2%%filedatetime:~3,2%%filedatetime:~6,4%

set /p message="Digite o comentário do commit: "

git add .
git commit -m "%message% %filedatetime%%username%"
git push

5

The date format/layout/strings in the variable %date% changes as: region, language and/or settings made by the user:


The variable %date% will always display the date in the format according language & country, or in a custom/user configured format, ie does not follow fixed layout/default, where we can work in a predictive way, and consequently manipulate the output string, relying on a fixed/predictable layout

I suggest using the wmic.exe, where, safely, you have a standardized and independent output of any region, language and/or any settings made by the user.

Using the wmic.exe to get the date in a reliable layout/format, where the user, language or region settings do not undergo any change...

References:

  • Alternative to compose date layout picking month/day with zero when less/equal 9:

set "filedatetime=!_day!-!_Month!-!_year!"
set "filedatetime=!_Month!/!_day!/!_year!"
set "filedatetime=!_year!-!_Month!-!_day!"
set "filedatetime=!_day!!_Month!!_year!"
set "filedatetime=!_Month!!_day!!_year!"
set "filedatetime=!_year!!_Month!!_day!"

  • Example using zero for mês/dia >=9 and also picking up/setting the variables Year, Month and Day separately to assemble the desired date layout:
wmic.exe Path Win32_LocalTime Get Year,Month,Day

Porting to the /:


@echo off && setlocal EnableDelayedExpansion

@%__APPDIR__%mode.com con:cols=60 lines=8
title <nul & title Add Send Versionamento

for %%i in (Year,Month,Day)do for /f %%I in ('
%__APPDIR__%wbem\wmic.exe Path Win32_LocalTime Get "%%~i"^|%__APPDIR__%findstr.exe [0-9]
')do if not "%%~i"=="Year" (set "_%%~i=0%%~I" && call set "_%%~i=!_%%~i:~-2!") else set "_%%~i=%%~I"

rem :: Obs.: Invertendo a data e usando zero: ano/ 0+mês/ 0+dia,  ::
rem :: Vai obter um mesmo número de dígitos e sempre crescente. ::
set "filedatetime=!_year!!_Month!!_day!" 

cd /d "C:\xampp\htdocs\laravelapi"

:loop
echo/ & set /p "_message="Digite Mensagem: "
echo/!_message!|%__APPDIR__%findstr.exe [a-Z] >nul || cls && goto :loop

cmd.exe /v /c git add .
cmd.exe /v /c git commit -m "!_message! Ref: !filedatetime!/%username%"
cmd.exe /v /c git push

%__APPDIR__%timeout.exe -1 & endlocal && goto :EOF

  • For input: Versão de !date!

  • Commando: git commit -m "!_message! Ref: !filedatetime!/%username%", Results:

"Versão de 2020-02-19 Ref: 20200219/ecker"

Obs.:

set /p does not return any indication stating that the user has entered a set of characters,or the Enter only, where, some additional commands are can be used to check whether the input (variable: !_message! ) has actually received value/characters....

  • Taking the date in a predictive format, in predictable and reliable layout

  • Obtains looping inputs, which will verify the presence or not of characters

  • Prevents execution of next commands when input is null/character free

  • Stay looped if user does not type anything and/or just press ENTER


inserir a descrição da imagem aqui


@echo off && setlocal EnableDelayedExpansion

@%__APPDIR__%mode.com con:cols=60 lines=8
title <nul & title Add Send Versionamento

cd /d "C:\xampp\htdocs\laravelapi"
for /f "tokens=2delims==." %%i in (
'%__APPDIR__%\wbem\wmic.exe OS Get localdatetime /value^|findstr [0-9]'
) do set "_d=%%i" && call set "filedatetime=!_d:~6,2!!_d:~4,2!!_d:~0,4!

echo/ Data Layout : !_d:~6,2!/!_d:~4,2!/!_d:~0,4!- !_d:~8,2!:!_d:~10,2!]

:loop
echo/ & set /p "_message="Digite Mensagem: "
echo/!_message!|%__APPDIR__%findstr.exe [a-Z] >nul || cls && goto :loop

cmd.exe /v /c git add .
cmd.exe /v /c git commit -m "!_message! Ref: !filedatetime!/%username%"
cmd.exe /v /c git push

%__APPDIR__%timeout.exe -1 & endlocal & goto :EOF

  • Or with a hybrid input box with VBS:
<!-- ::  
@%__APPDIR__%mode.com con:cols=60 lines=8
@echo off && setlocal EnableDelayedExpansion

title <nul & title Add Send Versionamento

cd /d "C:\xampp\htdocs\laravelapi"
for /f "tokens=2delims==." %%i in (
'%__APPDIR__%\wbem\wmic.exe OS Get localdatetime /value^|findstr [0-9]'
) do set "_d=%%i" && call set "filedatetime=!_d:~6,2!!_d:~4,2!!_d:~0,4!

echo/ Data Layout : !_d:~6,2!/!_d:~4,2!/!_d:~0,4!- !_d:~8,2!:!_d:~10,2!

:loop
for /f "tokens=*delims= " %%i in ('%__APPDIR__%CScript.exe //NoLogo "%~f0?.wsf"')do set "_message=%%~i"
echo/!_message!|%__APPDIR__%findstr.exe [a-Z] >nul || goto :loop

cmd.exe /v /c git add .
cmd.exe /v /c git commit -m "!_message! Ref: !filedatetime!/%username%"
cmd.exe /v /c git push

%__APPDIR__%timeout.exe -1 & endlocal & goto :EOF
# --><job><script language="vbscript">
Input=InputBox("Digite Mensagem: ", "Novo Versionamento: "): wsh.echo Input: Set Input=Nothing
</script></job>

  • Input/output:

inserir a descrição da imagem aqui

  • 4

    No, my answer does not work for other date or culture formats, and it is not necessary to do that either. I answered what the author asked, and did not emphasize the answer with things that would be unnecessary to him. It seems that it will be for personal use and therefore will not have constant culture/date change, will always expect something from the system. And if he wants to do something more comprehensive, another more specific question would be asked. A simple question can get a simple answer.

  • 4

    If I don’t understand, explain. What I understand is that you want me to make my answer broad enough to be polluted enough to not even answer the author’s question by adding unnecessary content. And on "support," if that’s a vote for you, I suggest you’re misusing the site. Votes should not be personal or intrapersonal, but according to the content.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.