Skip to content

Instantly share code, notes, and snippets.

@michaldarda
Last active August 29, 2015 14:11
Show Gist options
  • Save michaldarda/7a1b14fba658b8e52f1e to your computer and use it in GitHub Desktop.
Save michaldarda/7a1b14fba658b8e52f1e to your computer and use it in GitHub Desktop.
" First, add this to zsh or bashrc
" export CDPATH=$CDPATH:~/projects/main:~/projects/testing:~/projects/documentation:~/projects/gems:~/projects/support:~/projects/deployment
function! ChangeProject(target)
execute "cd " . a:target
edit .
endfunction
function! DirsCdPath()
let paths = split(globpath(&cdpath, '*'), '\n')
let result = []
for path in paths
if isdirectory(path)
let result += [path]
endif
endfor
return result
endfunction
function! DirInCdPathCompletion(ArgLead, CmdLine, CursorPos)
let result = []
for path in DirsCdPath()
if path =~ a:ArgLead
let result += [fnamemodify(path, ':t')]
end
endfor
return join(result, "\n")
endfunction
command! -nargs=1 -complete=custom,DirInCdPathCompletion ChangeProject call ChangeProject(<q-args>)
cabbr p ChangeProject
function! OpenFileInCWD(filename)
let l:current_working_dir = getcwd()
let l:filepath = l:current_working_dir . '/' . a:filename
if filereadable(l:filepath)
execute "edit " . l:filepath
else
echom "File " . l:filepath . " doesn't exists"
endif
endfunction
function! Rgemfile()
call OpenFileInCWD("Gemfile")
endfunction
function! Rgemfilelock()
call OpenFileInCWD("Gemfile.lock")
endfunction
command! Rgemfile call Rgemfile()
command! Rglock call Rgemfilelock()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment