forked from cknadler/vim-anywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·145 lines (118 loc) · 3.78 KB
/
install
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#
# vim-anywhere - use Vim whenever, wherever
# Author: Chris Knadler
# Homepage: https://www.github.com/cknadler/vim-anywhere
#
# Installs vim-anywhere. Intended for use via curl:
#
# $ curl -fsSL https://raw.github.com/cknadler/vim-anywhere/master/install | bash
set -e
###
# opts
###
while getopts ":v" opt; do
case "$opt" in
v) set -x ;;
\?) echo "Invalid option: -$OPTARG" >&2 ;;
esac
done
###
# defs
###
err() { echo -e "$@" 1>&2; }
check_installed() { hash $1 &> /dev/null; }
require_installed() {
if ! check_installed $1; then
err "vim-anywhere requires $1 to function"
if [[ "$2" != "" ]]; then echo $2; fi
exit 1
fi
}
require_one_installed() {
for file in $*; do
check_installed $file && return
done
err "vim-anywhere requires one of the following to be installed:\n$*"
exit 1
}
AW_PATH=$HOME/.vim-anywhere
AW_URL='https://github.com/cknadler/vim-anywhere'
###
# pre-installation checks
###
# Check if vim-anywhere is already installed. If so, remove the previous
# installation.
if [ -a $AW_PATH ]; then
echo 'Cleaning up previous installation...'
rm -rf $AW_PATH
# TODO: It would be nice to have an option for user input here
# Reinstall vim-anywhere (y/n)? ... or something like that
fi
require_installed git
# if we are in a git repo, unset env vars
if git rev-parse --git-dir &> /dev/null; then
unset $(git rev-parse --local-env-vars) &> /dev/null
fi
# Linux specific checks
if [[ $OSTYPE == "linux-gnu" ]]; then
require_one_installed gconftool gsettings
require_installed gvim
require_installed xclip
# OSX specific checks
elif [[ $OSTYPE == "darwin"* ]]; then
require_installed mvim 'Run `brew install macvim`.'
# Unsupported OS
else
echo "OS '$OSTYPE' is not supported!"
exit 1
fi
###
# installation
###
echo "Installing vim-anywhere..."
git clone $AW_URL $AW_PATH
# Linux install
if [[ $OSTYPE == "linux-gnu" ]]; then
name="vim-anywhere"
binding="<CTRL><ALT>v"
action=$AW_PATH/bin/run
# We always try gconftool first. It is deprecated so it won't be on newer
# installs. If it's installed, we know we are on older versions of Gnome.
if check_installed gconftool; then
kbd_path=/desktop/gnome/keybindings/vim-anywhere
gconftool -t str --set $kbd_path/name $name
gconftool -t str --set $kbd_path/binding $binding
gconftool -t str --set $kbd_path/action $action
# At this point, we know we are using dconf, the currently supported settings
# manager. gsettings is the gnome client for dconf.
else
media_keys=org.gnome.settings-daemon.plugins.media-keys
custom_kbd=org.gnome.settings-daemon.plugins.media-keys.custom-keybinding
kbd_path=/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/vim-anywhere/
new_bindings=`gsettings get $media_keys custom-keybindings | sed -e"s>'\]>','$kbd_path']>"| sed -e"s>@as \[\]>['$kbd_path']>"`
gsettings set $media_keys custom-keybindings "$new_bindings"
gsettings set $custom_kbd:$kbd_path name $name
gsettings set $custom_kbd:$kbd_path binding $binding
gsettings set $custom_kbd:$kbd_path command $action
fi
# OSX install
elif [[ $OSTYPE == "darwin"* ]]; then
# store the absolute path to the mvim executable
which mvim > $AW_PATH/.path
# install the workflow as a service
mkdir -p $HOME/Library/Services
cp -R $AW_PATH/VimAnywhere.workflow $HOME/Library/Services
# Set default keybindings
defaults write pbs NSServicesStatus '{
"(null) - VimAnywhere - runWorkflowAsService" = {
"key_equivalent" = "@^v";
};
"org.vim.MacVim - MacVim/New MacVim Buffer With Selection - openSelection" = {
"key_equivalent" = "@^v";
};
}'
# Activating Finder causes the new keybindings to become active
osascript -e "activate application \"Finder\""
fi
echo "vim-anywhere has been successfully installed!"