Last active
October 31, 2022 17:53
-
-
Save bantya/2993ff4f377f3bd563cb6d9e6f4a3459 to your computer and use it in GitHub Desktop.
BAT: My custom bat commands to make life easier.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Easy change directory command for cmd | |
:: Created: 23062017 | |
set Dir=%1 | |
if "%Dir%"=="" ( | |
cd | |
) else ( | |
cd /d %1 | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Easily jump to the \CustomCMDCommands\ | |
cd /d "%~dp0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Copy files / folders. | |
:: Created: 23062017 | |
copy %1 %2 %3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To copy the current cmd path or the executable path (e.g. php, mysql path) | |
:: -a => Copy all the lines | |
:: -f => Copy the result w/o ant bat or cmd file path. | |
:: This file requires another helper file wher-sup.bat | |
:: updated: 23062017 | |
if "%1"=="" ( | |
cd | clip | |
echo. Copied the current path! | |
) else ( | |
if "%2"=="-a" ( | |
where %1 | clip | |
echo. Copied the all paths! | |
) else if "%2"=="-f" ( | |
where "%1" | findstr /v .bat | findstr /v .cmd | clip | |
echo. Copied the first path! | |
) else ( | |
wher-sup %1 | |
echo. Copied the specified path! | |
) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Alias for cpath command (cp === copy path) | |
:: Created: 23062017 | |
cpath %1 %2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To enable Windows create and edit the files directly from cmd using Vim | |
vim %1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Start a process/app elevated from command line | |
:: Helpful in cases where one has to edit system ( e.g. hosts) files. | |
set App=%1 | |
set File=%2 | |
if "%App%"=="" ( | |
goto eof | |
) | |
if "%File%"=="hosts" ( | |
set File="c:\windows\system32\drivers\etc\hosts" | |
) | |
powershell -Command "Start-Process -FilePath %App% %File% -Verb runAs" | |
:: powershell.exe -Command "Start-Process cmd \"/k cd /d %cd%\" -Verb RunAs" | |
:: powershell -Command "Start-Process cmd -ArgumentList '/K cd %cd%' -Verb RunAs " | |
:eof |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Easy git clone command | |
:: created 24042017 | |
:: updated 29092017 Added facility to clone a repo using uername/reponame | |
:: http://stackoverflow.com/questions/7005951/batch-file-find-if-substring-is-in-string-not-in-a-file | |
set url=%1 | |
set location=%2 | |
echo %url% | find /I "https://github.com/">Nul | |
if errorlevel 1 ( | |
set url=https://github.com/%url%.git | |
) | |
echo %url% | find /I ".git">Nul | |
if errorlevel 1 ( | |
set url=%url%.git | |
) | |
git clone %url% %location% | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Alias for cdir command (here gf === go to folder) | |
:: Created: 23062017 | |
cdir %1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: List directory content in bash fashion | |
set dir=%1 | |
dir /d /og /on %dir% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Alias for ldir command (lf === list folders) | |
:: Created: 23062017 | |
set dir=%1 | |
ldir %dir% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Move files / folders. | |
:: Created: 23062017 | |
move %1 %2 %3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To open current directory directly from cmd | |
set Location=%1 | |
if "%Location%"=="" set Location=. | |
start %Location% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To get the parent folder from current file / folder path (helper file for cppath.bat) | |
set Loc=%1 | |
echo %~dp1 | clip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To emulate PHP console interactive mode on Windows | |
:: From: https://stackoverflow.com/a/26989684/5490303 | |
echo Interactive mode enabled | |
echo. | |
:loop | |
set /p php="php > " %=% | |
php -r "%php%" | |
echo. | |
goto loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Open desired file with phpstorm easily | |
phpstorm64 %1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Easy remove directory command | |
:: Created: 24042017 | |
:: http://stackoverflow.com/questions/3732947/batch-to-remove-character-from-a-string | |
set Dir=%1 | |
if %Dir:~-1%==\ set Dir=%Dir:~0,-1% | |
if %Dir:~-1%==/ set Dir=%Dir:~0,-1% | |
rd %Dir% /s | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Restart explorer.exe to prevent restarting computer. | |
:: Created: 19072017 | |
taskkill /f /im explorer.exe | |
start explorer.exe | |
exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Alias for rdir command (rf === remove folder) | |
:: Created: 23062017 | |
rdir %1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: rrurl: remote repo url opener. | |
:: Rahul Thakare <https://github.com/bantya> 11-02-2019 | |
:: Ref. https://www.dostips.com/DtTipsStringManipulation.php | |
git remote get-url origin > tmpFile | |
set /p repo=<tmpFile | |
del tmpFile | |
echo %repo% | find /I "[email protected]:">Nul | |
set repo=%repo:[email protected]:=% | |
set repo=%repo:https://github.com/=% | |
set repo=%repo:.git=% | |
echo Opening: https://github.com/%repo% | |
start https://github.com/%repo% | |
set "repo=" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Open the local spotlight images folder | |
:: Created: 04092017 | |
start %localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To open desired file with sublime text with desired attributes | |
set Location=%1 | |
set Command=%2 | |
if "%Location%"=="" set Location=. | |
if "%Command%"=="" set Command=-a | |
if %Location:~0,1%==- ( | |
set Command=%Location% | |
set Location=. | |
) | |
subl %Location% %Command% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To unzip the .zip archive | |
:: Updated: 29082017 | |
set Source=%1 | |
set Destination=%2 | |
set CD=%cd% | |
if "%Destination%"=="" ( | |
set Filename=%~nx1 | |
set Destination=%CD%\%Filename:.zip=% | |
) else ( | |
set "Destination=%Destination:\=/%" | |
set Destination=%CD%\%Destination% | |
) | |
set Expr=ExtractToDirectory('%Source%', '%Destination%') | |
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::%Expr%; }" | |
echo. | |
echo.Done unzipping! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To download file natively in cmd as Windows did not have any alternative to wget. | |
setLocal EnableDelayedExpansion | |
set Url=%1 | |
set Url=!Url:http://=! | |
set Url=!Url:/=,! | |
set Url=!Url:%%20=?! | |
set Url=!Url: =?! | |
call :LOOP !Url! | |
set FileName=%2 | |
if "%2"=="" set FileName=!FN! | |
echo. | |
echo.Downloading: [1;34m%1[0m to [1;34m\!FileName![0m | |
powershell.exe -command wget %1 -OutFile !FileName! | |
goto :EOF | |
:LOOP | |
if "%1"=="" goto :EOF | |
set FN=%1 | |
set FN=!FN:?= ! | |
shift | |
goto :LOOP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: To get the filepath from where command as a variable (helper file for cppath.bat) | |
:: This file requires another helper file parent.bat | |
where %1 > tmpFile | |
set /p App= < tmpFile | |
del tmpFile | |
parent %App% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Get the Windows user name or group information. | |
:: Updated: 23062017 | |
set Args=%1 | |
if "%Args%"=="-n" ( | |
hostname | |
goto eof | |
) | |
if "%Args%"=="-a" set Args="/all" | |
if "%Args%"=="-u" set Args="/user" | |
if "%Args%"=="-p" set Args="/priv" | |
whoami %Args% | |
:eof |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:: Author: Rahul Thakare | |
:: Email: [email protected] | |
:: Github: www.github.com/bantya | |
:: Purpose: Zip the entire content of the desired directory | |
set Source=%1 | |
set Destination=%2 | |
if "%Source%"=="" set Source=. | |
if "%Destination%"=="" set Destination=Zipped.zip | |
echo %Destination% | find /I ".zip">Nul | |
if errorlevel 1 ( | |
set Destination=%Destination%.zip | |
) | |
set Expr=CreateFromDirectory('%Source%', '%Destination%') | |
powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::%Expr%; }" | |
echo. | |
echo.Done zipping! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anybody have such useful bat scripts then please add here.