Skip to content

Instantly share code, notes, and snippets.

@chikuchikugonzalez
Created August 5, 2014 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chikuchikugonzalez/d3d3f5fbbc8fbf1e9bf7 to your computer and use it in GitHub Desktop.
Save chikuchikugonzalez/d3d3f5fbbc8fbf1e9bf7 to your computer and use it in GitHub Desktop.
pecoでディレクトリを選択してcdするスクリプト (Windowsバッチファイル)
@echo off
:: pecoってディレクトリ移動をするスクリプト.
::
:: TODO 文字化けしてた('A`)
:init
set _pecocd_flags=
set _pecocd_folder=%CD%
:args
if "%1"=="" goto :peco
for /F "delims=/- tokens=1,2*" %%i in ("%1") do (
if "%%i"=="%1" (
set _pecocd_folder=%1
goto :peco
) else (
if "%%i"=="?" goto :usage
set _pecocd_flags=%_flags% %1
)
)
shift /1
goto :args
:peco
for /F "usebackq" %%i in (`dir /AD /B %_pecocd_flags% %_pecocd_folder% ^| peco`) do (
if exist "%_pecocd_folder%\%%i" (
cd /D "%_pecocd_folder%\%%i"
) else if exist "%%i" (
cd /D "%%i"
)
goto :clean
)
:clean
set _pecocd_flags=
set _pecocd_folder=
goto :finish
:usage
echo USAGE: %0 [dir options] [/?] [folder]
echo.
echo Examples:
echo pecd C:\
echo pecd /S C:\ # Very Slow
echo.
:finish
exit /B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment