[cmake-developers] zsh user out there ?

Ben Boeckel mathstuf at gmail.com
Tue Jun 22 20:02:46 EDT 2010


Sorry for the self-reply, but I thought these might also be useful:

------ ZSH -----------------------

# Directory changing stuff
alias cb="cd src build"
alias cs="cd build src"
alias cdp="cd \$PWD"
alias dcl="dirs -c"
mcwd () {
    cb || exit 1
    make "$@"
    popd
}

------ VIM -----------------------

" Support cmake builds
function! Cmake(args)
    execute ':make -C "%:p:h:s/src/build/"' a:args
endfunction
function! MakeShortcut()
    if filereadable(fnamemodify('%', ':h') . '/Makefile')
        nmap <F8> :make<CR>
    elseif filereadable(fnamemodify('%', ':h') . '/CMakeLists.txt')
        nmap <F8> :Cmake<CR>
    elseif expand("%:e") == "tex"
        nmap <F8> :!pdflatex %<CR>
    else
        nmap <F8> <Nop>
    endif
endfunction
command! -nargs=* Cmake              call Cmake(<q-args>)

" <snip>

" Make/CMake support
autocmd FileType * :call MakeShortcut()

------ END -----------------------

These assume the following:

  * A project has a directory (~/code/foo)
  * In this directory, the repo checkout is in src (~/code/foo/src)
  * In this directory, the build directory is in build (~/code/foo/build)
  * Your cmake build dir is already configured and generated

Usage is then:

  * cs: goes from build -> src directory
      - ~/code/foo/build/doc -> ~/code/foo/src/doc
  * cb: goes from src -> build directory
      - ~/code/foo/src/doc -> ~/code/foo/build/doc
  * mcwd: execute make in the build dir of the current directory
      - The following:
            ~/code/foo/src/doc % mcwd doc
        is as if you did:
            make doc
        in
            ~/code/foo/build/doc

      - Assumes you have:
            setopt autopushd
        The dcl alias clears the stack when it gets unweildly.
  * The vim magic is similar. Dynamically bind <F8> (normal mode) to
    build. Use cmake (act similar to mcwd, but use the current file as
    the src directory), plain make, or LaTeX depending on the what's
    found laying around.

Hope this helps. I've found them to be invaluable.

--Ben




More information about the cmake-developers mailing list