git-control.vim 1.65 KB
Newer Older
Moritz Sokoll's avatar
Moritz Sokoll committed
1
2
" Name: git-control
" Author: Moritz Sokoll
Moritz Sokoll's avatar
Moritz Sokoll committed
3
" Description: a git version control integration for vim
Moritz Sokoll's avatar
Moritz Sokoll committed
4
5
6
7
8
9
10

if exists('g:git_control_loaded')
	finish
endif

function! Git_Commit()
	let commit_message = input('commit message: ')
Moritz Sokoll's avatar
Moritz Sokoll committed
11
	echo ''
Moritz Sokoll's avatar
ye    
Moritz Sokoll committed
12
	if len(commit_message) < 1
Moritz Sokoll's avatar
Moritz Sokoll committed
13
		echo 'message too short'
Moritz Sokoll's avatar
Moritz Sokoll committed
14
15
16
17
18
19
	else
		let stat = system("git commit -am '" . commit_message . "'")
		echo stat
	endif
endfunction

Moritz Sokoll's avatar
Moritz Sokoll committed
20
function! Git_Push()
Moritz Sokoll's avatar
Moritz Sokoll committed
21
22
23
24
25
26
27
28
29
	let remote = input('remote (default is origin): ')
	echo ''
	if len(remote) == 0
		let remote = 'origin'
	elseif matchstr(remote, ' ') == ' '
		echo 'remote name cannot have a space in it'
		return
	endif
	echo system('git push ' . remote)
Moritz Sokoll's avatar
Moritz Sokoll committed
30
31
32
33
34
35
36
37
38
39
endfunction

function! Git_Checkout()
	let branch_name = input('branch: ')
	echo ''
	if len(branch_name) < 1
		echo 'branch name too short'
	elseif matchstr(branch_name, ' ') == ' '
		echo 'branch names cannot have spaces in them'
	else
40
		let stat = system('git checkout ' . branch_name)
Moritz Sokoll's avatar
Moritz Sokoll committed
41
42
43
44
		echo stat
	endif
endfunction

45
46
47
48
49
50
51
52
53
54
55
56
57
function! Git_Branch()
	echo system('git branch --list')
	let branch_name = input('new branch name: ')
	echo ''
	if len(branch_name) < 1
		echo 'name too short'
	elseif matchstr(branch_name, ' ') == ' '
		echo 'branch name does not allow spaces'
	else
		echo system('git branch ' . branch_name)
	endif
endfunction

Moritz Sokoll's avatar
Moritz Sokoll committed
58
59
60
61
function! Git_Status()
	echo system('git status')
endfunction

62
63
64
65
function! Git_Log()
	echo system('git --no-pager log --pretty=oneline --graph')
endfunction

Moritz Sokoll's avatar
Moritz Sokoll committed
66
command! GitCommit call Git_Commit()
Moritz Sokoll's avatar
Moritz Sokoll committed
67
68
command! GitPush call Git_Push()
command! GitCheckout call Git_Checkout()
Moritz Sokoll's avatar
Moritz Sokoll committed
69
command! GitStatus call Git_Status()
70
71
command! GitBranch call Git_Branch()
command! GitLog call Git_Log()
Moritz Sokoll's avatar
Moritz Sokoll committed
72
let g:git_control_loaded = 1