-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathv
executable file
·91 lines (77 loc) · 1.67 KB
/
v
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
#!/bin/bash
function help {
echo "Usage:
V source [OPTIONS] [ARGUMENTS ... ]
Options:
-V Show warnings from vim
-v Run in verbose mode
-h Show this screen.
-x Print a hexdump of the source file encoded in latin1 to STDERR
-n Add a trailing newline to the output
-f FILE Open with FILE for input
"
exit
}
vim_cmds=()
args=()
file=""
newline=false
verbose=0
hexdump=0
keystroke_file=""
if [ "$#" == 0 ] ; then
help
fi
source="$1"
shift 1
while getopts "Vvnhxf:s:w:" arg; do
case $arg in
v)
verbose=1
;;
V)
vim_cmds+=(-V2 )
;;
x)
hexdump=true
keystroke_file=$(mktemp v.XXXX --tmpdir)
vim_cmds+=(-W $keystroke_file)
;;
f)
vim_cmds+=($OPTARG)
;;
n)
newline=true
;;
h)
help
;;
s)
>&2 echo "The -s flag is deprecated."
;;
w)
>&2 echo "The -w flag is deprecated."
;;
esac
done
shift $(($OPTIND-1))
function vim_escape () {
printf '"'
for (( i=0; i<${#1}; i++ )); do
printf '\\x%x' "'${1:$i:1}";
done
printf '"'
}
for (( i=1; i<$#+1; i++ )); do
args+=(-c 'call Set_Arg('$(vim_escape "${!i}")')')
done
export V="$(dirname -- "$(readlink -e -- "$0")")"
vim -Nnes "${vim_cmds[@]}" -u "$V/vim/init.vim" -i NONE "${args[@]}" -c "call Execute_Program('$source', '$verbose')" -c "%p" -c "q!" | head -c -1
if [ "$hexdump" = true ] ; then
# Convert the keystroke file
>&2 echo -e "\n\nHexdump:\n"
>&2 vim -u NONE -Nnes $keystroke_file -c "se fenc=latin1" -c "se binary" -c 'w' -c 'normal G$xxx' -c '1,$!xxd' -c '%norm 4I ' -c "%p" -c "q!"
fi
if [ "$newline" = true ] ; then
echo ""
fi