Skip to content
This repository has been archived by the owner on Jun 20, 2020. It is now read-only.

Latest commit

 

History

History
78 lines (60 loc) · 1.85 KB

vcs.asciidoc

File metadata and controls

78 lines (60 loc) · 1.85 KB

vcs.kak

Auto-detect and store the path to the root of the current repository, if any.

When a new buffer is created/opened, the script will try to use the following Version Control Systems, on after the other:

  • git

  • svn

  • hg

  • bzr

As soon as a VCS returns a path, indicating that the current buffer was created within a repository, the variable below is set.

Variables

vcs_name

String holding the name of the VCS detected. Can be one of:

  • git

  • svn

  • mercurial

  • bazaar

vcs_root_path

String containing the path to the repository in which the current buffer was created. This variable only has a value set in the buffer scope.

After the script has been loaded, one could use it in subsequent hooks to apply project-wide settings (c.f. example below).

Examples

Auto-detecting root tags files

Adding a tags file (for use with the builtin ctags support script) to the ctagsfiles option, on buffer creation:

hook global BufCreate .* %{
    %sh{
        if [ -e "${kak_opt_vcs_root_path}/tags" ]; then
            printf 'set-option -add buffer ctagsfiles %%{%s}\n' "${kak_opt_vcs_root_path}/tags"
        fi
    }
}

Highlighting git changes

Highlighting with a flag the lines that were changed, in a buffer, since the last git commit:

hook global WinCreate .* %{ evaluate-commands %sh{
    if [ -n "${kak_opt_vcs_root_path}" ]; then
        case "${kak_opt_vcs_name}" in
            git)
                echo "
                    git show-diff
                    hook global BufWritePost %val{buffile} %{git update-diff}
                    hook global BufReload %val{buffile} %{git update-diff}
                    hook global WinDisplay %val{buffile} %{git update-diff}
                ";;
        esac
    fi
} }