-
Notifications
You must be signed in to change notification settings - Fork 0
/
n1ql4vim
executable file
·99 lines (69 loc) · 2.02 KB
/
n1ql4vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
#
# Vim is Charityware. n1ql.vim syntax is Charityware.
#
# (c) Copyright 2017 by Eugene Ciurana / pr3d4t0r. Licensed under the
# standard VIM LICENSE - Vim command :help uganda.txt for details.
#
# Project: https://github.com/pr3d4t0r/n1ql-vim-syntax
N1QL_SYNTAX_PROJECT="https://github.com/pr3d4t0r/n1ql-vim-syntax.git"
# MacOS and Linux:
TMP_DIR=$(mktemp -d 2> /dev/null || mktemp -d -t 'n1ql')
USER_VIM="$HOME/.vim"
function die {
if [[ -z "$2" ]]
then
exitCode=99
else
exitCode="$2"
fi
echo "$1"
exit "$exitCode"
} # die
function assertVimDirExists {
[[ ! -d "$HOME/.vim" ]] && die "$HOME/.vim directory missing; create it to continue" 1
} # assertVimDirExists
function assertGitInstalled {
[[ -z $(which git) ]] && die "git command not found on this system" 2
} # assertGitInstalled
function setup {
rm -Rf "$TMP_DIR"
mkdir -p "$TMP_DIR"
} # setup
function cloneProject {
git clone "$N1QL_SYNTAX_PROJECT" "$TMP_DIR"
} # cloneProject
function _cleanCopy {
file="$1"
sourceFile="$2/$file"
targetFile="$3/$file"
# Always overrides - no check? Suggestions?
rm -f "$targetFile"
cp -vf "$sourceFile" "$targetFile"
} # _cleanCopy
function installSyntaxFiles {
vimSyntax="$USER_VIM/syntax"
vimFileDetection="$USER_VIM/ftdetect"
vimDocs="$USER_VIM/doc"
originSyntax="$TMP_DIR/syntax"
originFileDetection="$TMP_DIR/ftdetect"
originDocs="$TMP_DIR/doc"
_cleanCopy n1ql.vim "$originSyntax" "$vimSyntax"
_cleanCopy n1ql.vim "$originFileDetection" "$vimFileDetection"
_cleanCopy n1ql.txt "$originDocs" "$vimDocs"
} # installSyntaxFiles
function notify {
printf "N1QL Vim syntax files installed in $USER_VIM\n\n"
[[ -n $(which tree) ]] && tree -L 2 -I "autoload*|snippets*|include*|lib*|nerdtree*|*plugin*" -P "n1ql.*" "$USER_VIM"
} # notify
function cleanUp {
rm -Rf "$TMP_DIR"
} # cleanUp
# *** main ***
assertVimDirExists
assertGitInstalled
setup
cloneProject
installSyntaxFiles
notify
cleanUp