-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathADD_TO_VIM.sh
More file actions
executable file
·60 lines (57 loc) · 1.92 KB
/
Copy pathADD_TO_VIM.sh
File metadata and controls
executable file
·60 lines (57 loc) · 1.92 KB
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
#!/bin/bash
vimrcfile="$HOME/.vimrc"
if [ ! -f ./rcup.py ]
then
echo >&2 'Please cd into the bundle before running this script.'
exit 1
elif [ ! -f "$vimrcfile" ]
then
echo >&2 'No .vimrc file in your home directory.'
exit 1
else
echo >&2 'Adds an autocommand to your .vimrc to use "sync-nhrc" (via the rcup.py script)'
echo >&2 'to sync remote files with your local copy whenever ~/.nethackrc is saved.'
echo >&2
echo >&2 'NB: this will write your username & password in plaintext to your .vimrc!!'
echo >&2
servers=""
read -p'alt.org username (blank skips): ' -e nao_user
if test -n "$nao_user"; then
read -p'alt.org password (blank skips): ' -es nao_pass
echo
if test -n "$nao_pass"; then
servers=" nao"
else
nao_user=
fi
fi
read -p'hardfought username (blank skips): ' -e hdf_user
if test -n "$hdf_user"; then
read -p'hardfought password (blank skips): ' -es hdf_pass
echo
if test -n "$hdf_pass"; then
servers="$servers$([ -n "$servers" ] && printf " and " || printf " ")hdf"
else
hdf_user=
fi
fi
if [ -z "$servers" ]; then
echo >&2 "no servers selected. goodbye"
exit 0
fi
printf >>"$vimrcfile" '" keep .nethackrc updated on%s via sync-nhrc\n' "$servers"
autocmd=""
if [ "$hdf_user" = "$nao_user" ] && [ "$hdf_pass" = "$nao_pass" ]; then
autocmd="$PWD/rcup.py -sHa $nao_user '$nao_pass' &"
else
if [ -n "$nao_user" ]; then
autocmd="$PWD/rcup.py --silent --nao --no-hdf $nao_user '$nao_pass' &"
fi
if [ -n "$hdf_user" ]; then
autocmd="${autocmd}$([ -n "$autocmd" ] && echo "; ")$PWD/rcup.py --silent --no-nao --hdf $hdf_user '$hdf_pass' &"
fi
fi
echo >>"$vimrcfile" "autocmd! BufWritePost ~/.nethackrc sil!!$autocmd"
echo >&2
echo >&2 'Done.'
fi