-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvivimctl
executable file
·87 lines (75 loc) · 2.2 KB
/
vivimctl
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
#!/bin/bash
# vim: set ft=sh:
# Init VIVIMCTL --------------------------------------------------------------
VERSION="v0.1.1"
# env
if [[ -f $HOME/.vivimrc ]]; then source $HOME/.vivimrc; fi
VIVIM_PATH=${VIVIM_PATH:="."}
# error
function error_unknown_command() {
local command="$1"
local subcommand="$2"
echo "error: Unknown subcommand or option \"$subcommand\" for \"$command\"" 1>&2
}
# dependency check
DIFF_CMD="colordiff"
if ! `colordiff --version &> /dev/null`; then DIFF_CMD="diff --color"; fi
# SUBCOMMAND vimrc -----------------------------------------------------------
source $VIVIM_PATH/vimrc/vimrc.vivimctl
# SUBCOMMAND zshrc -----------------------------------------------------------
source $VIVIM_PATH/zshrc/zshrc.vivimctl
# SUBCOMMAND install ---------------------------------------------------------
function install() {
case "$1" in
"")
local vivim_abs_path=$(cd `dirname $0` && pwd)
local vivim_install_path="/usr/local/bin/vivimctl"
echo "VIVIM_PATH='$vivim_abs_path'" > $HOME/.vivimrc
sudo ln -sf $vivim_abs_path/vivimctl /usr/local/bin/vivimctl && echo "vivimctl installed."
;;
*)
echo "error: No subcommand or option available for command \"vivimctl install\""
exit 1
;;
esac
}
# Main -----------------------------------------------------------------------
function main() {
case "$1" in
vimrc)
vimrc $2
;;
zshrc)
zshrc $2
;;
install)
install $2
;;
help | --help | -H)
main_help
;;
version | --version | -V)
main_version
;;
*)
error_unknown_command "vivimctl" "$1"
exit 1
;;
esac
}
function main_help() {
cat << EOF | column -t -s '|'
SUBCOMMAND|DESCRIPTION
install|Install vivimctl by creating symlink in /usr/bin
version (--version, -V)|Print VIVIMCTL version
vimrc|Manage vim configuration file (vimrc)
zshrc|Manage zsh configuration file (zshrc)
EOF
}
function main_version() {
cat << EOF
VIVIMCTL version $VERSION
VIVIM directory path: $VIVIM_PATH
EOF
}
main $@