Created
March 18, 2009 13:03
-
-
Save ubermuda/81105 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
"------------------------------------------------------------------------------- | |
" Description: Finds and cd to the symfony root of the project | |
" Copyright: Copyright (C) 2009 Geoffrey Bachelet | |
" Maintainer: Geoffrey Bachelet | |
" Version: 1.0 | |
"------------------------------------------------------------------------------- | |
if exists('find_symfony_root_loaded') | |
finish | |
endif | |
let find_symfony_root_loaded = 1 | |
if ! exists('find_symfony_root_symfony_executable') | |
let find_symfony_root_symfony_executable = 'symfony' | |
endif | |
" root detection when opening a new vim seems to work | |
" only if these two events are bound. not sure why. | |
autocmd BufWinEnter,BufRead * call FindSymfonyRoot() | |
function FindSymfonyRoot() | |
let l:cwd = GetAbsoluteDirname(@%) | |
let l:symfony_root = findfile(g:find_symfony_root_symfony_executable, l:cwd.';') | |
let l:symfony_root = GetAbsoluteDirname(l:symfony_root) | |
if strlen(l:symfony_root) != 0 | |
execute 'cd '.l:symfony_root | |
endif | |
endfunction | |
function GetAbsoluteDirname(path) | |
let l:path = a:path | |
" gets the dirname | |
if !isdirectory(l:path) | |
let l:path = strpart(l:path, 0, strridx(l:path, '/')) | |
endif | |
" makes it absolute | |
if match(l:path, '/') != 0 | |
let l:path = getcwd().'/'.l:path | |
endif | |
return l:path | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment