Skip to content

Instantly share code, notes, and snippets.

@jeremysimmons
Created May 21, 2024 19:09
Show Gist options
  • Save jeremysimmons/0ee0b0fb0a394f56783b0bcd2dbef12f to your computer and use it in GitHub Desktop.
Save jeremysimmons/0ee0b0fb0a394f56783b0bcd2dbef12f to your computer and use it in GitHub Desktop.
cdtilde recipe
@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%"
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
@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