Created
May 21, 2024 19:09
-
-
Save jeremysimmons/0ee0b0fb0a394f56783b0bcd2dbef12f to your computer and use it in GitHub Desktop.
cdtilde recipe
This file contains 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 | |
:: https://stackoverflow.com/a/52688643/26877 | |
set dirname="" | |
set dirname=%* | |
set orig_dirname=%* | |
:: remove quotes - will re-attach later. | |
set dirname=%dirname:\"=% | |
set dirname=%dirname:/"=% | |
set dirname=%dirname:"=% | |
:: restore dirnames that contained only "/" | |
if "%dirname%"=="" set dirname=%orig_dirname:"=% | |
:: strip trailing slash, if longer than 3 | |
if defined dirname if NOT "%dirname:~3%"=="" ( | |
if "%dirname:~-1%"=="\" set dirname="%dirname:~0,-1%" | |
if "%dirname:~-1%"=="/" set dirname="%dirname:~0,-1%" | |
) | |
set dirname=%dirname:"=% | |
:: if starts with ~, then replace ~ with userprofile path | |
if %dirname:~0,1%==~ ( | |
set dirname="%USERPROFILE%%dirname:~1%" | |
) | |
set dirname=%dirname:"=% | |
:: replace forward-slashes with back-slashes | |
set dirname="%dirname:/=\%" | |
set dirname=%dirname:"=% | |
chdir /D "%dirname%" |
This file contains 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
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_EXPAND_SZ /d "%"USERPROFILE"%\init.cmd" /f | |
reg delete "HKCU\Software\Microsoft\Command Processor" /v AutoRun | |
https://stackoverflow.com/a/17405182/26877 |
This file contains 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 | |
DOSKEY cd=cdtilde.bat $* | |
DOSKEY cd~=chdir /D "%USERPROFILE%" | |
DOSKEY cd..=chdir .. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment