Skip to content

Instantly share code, notes, and snippets.

@momo-lab
Created May 16, 2012 08:29
Show Gist options
  • Save momo-lab/2708705 to your computer and use it in GitHub Desktop.
Save momo-lab/2708705 to your computer and use it in GitHub Desktop.
Eclipseのプロジェクト/Subversion/Gitのルートに移動するWindows用バッチファイル
@ECHO OFF
REM プロジェクトのルートディレクトリに移動する。
REM PUSHDしてあるので、元のディレクトリに戻りたい場合はPOPDすればよい。
REM
REM ルートディレクトリの定義(上位ほど優先順位高)
REM .projectファイルがある(Eclipseのプロジェクトルート)
REM .gitディレクトリがある(gitのルート)
REM .svnディレクトリがあるtrunkディレクトリ(svnのルート)
PUSHD .
:LOOP
CALL :IS_PROJECT_ROOT
IF ERRORLEVEL 1 (
CD %CD%
EXIT /B 0
)
REM ドライブのルートディレクトリまで来てしまったら止める
IF "%CD:~-2,1%" == ":" GOTO :END_LOOP
CD ..
GOTO :LOOP
:END_LOOP
POPD
GOTO :EOF
:IS_PROJECT_ROOT
CALL :IS_ECLIPSE_PROJECT_ROOT %CD%
IF ERRORLEVEL 1 EXIT /B 1
CALL :IS_GIT_PROJECT_ROOT %CD%
IF ERRORLEVEL 1 EXIT /B 1
CALL :IS_SVN_PROJECT_ROOT %CD%
IF ERRORLEVEL 1 EXIT /B 1
EXIT /B 0
GOTO :EOF
:IS_ECLIPSE_PROJECT_ROOT
IF EXIST %1\.project EXIT /B 1
EXIT /B 0
GOTO :EOF
:IS_GIT_PROJECT_ROOT
IF EXIST %1\.git\CON EXIT /B 1
EXIT /B 0
GOTO :EOF
:IS_SVN_PROJECT_ROOT
IF NOT EXIST %1\.svn\CON EXIT /B 0
IF "%~nx1" == "trunk" EXIT /B 1
EXIT /B 0
GOTO :EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment