Created
August 5, 2014 15:51
-
-
Save chikuchikugonzalez/d3d3f5fbbc8fbf1e9bf7 to your computer and use it in GitHub Desktop.
pecoでディレクトリを選択してcdするスクリプト (Windowsバッチファイル)
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 | |
:: 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