2012-03-20 12:16:44 +00:00
|
|
|
#
|
|
|
|
# See README.md
|
|
|
|
#
|
|
|
|
# Derek Wyatt (derek@{myfirstnamemylastname}.org
|
|
|
|
#
|
|
|
|
|
|
|
|
function resolveFile
|
|
|
|
{
|
|
|
|
if [ -f "$1" ]; then
|
|
|
|
echo $(readlink -f "$1")
|
2012-03-20 13:55:25 +00:00
|
|
|
elif [[ "${1#/}" == "$1" ]]; then
|
2014-10-09 11:55:50 +00:00
|
|
|
echo "$PWD/$1"
|
2012-03-20 12:16:44 +00:00
|
|
|
else
|
2012-03-20 13:55:25 +00:00
|
|
|
echo $1
|
2012-03-20 12:16:44 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function callvim
|
|
|
|
{
|
|
|
|
if [[ $# == 0 ]]; then
|
|
|
|
cat <<EOH
|
|
|
|
usage: callvim [-b cmd] [-a cmd] [file ... fileN]
|
|
|
|
|
|
|
|
-b cmd Run this command in GVIM before editing the first file
|
|
|
|
-a cmd Run this command in GVIM after editing the first file
|
|
|
|
file The file to edit
|
|
|
|
... fileN The other files to add to the argslist
|
|
|
|
EOH
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local cmd=""
|
2012-04-01 19:41:39 +00:00
|
|
|
local before="<esc>"
|
2012-03-20 12:16:44 +00:00
|
|
|
local after=""
|
|
|
|
while getopts ":b:a:" option
|
|
|
|
do
|
|
|
|
case $option in
|
|
|
|
a) after="$OPTARG"
|
|
|
|
;;
|
|
|
|
b) before="$OPTARG"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
if [[ ${after#:} != $after && ${after%<cr>} == $after ]]; then
|
|
|
|
after="$after<cr>"
|
|
|
|
fi
|
|
|
|
if [[ ${before#:} != $before && ${before%<cr>} == $before ]]; then
|
|
|
|
before="$before<cr>"
|
|
|
|
fi
|
|
|
|
local files=""
|
|
|
|
for f in $@
|
|
|
|
do
|
|
|
|
files="$files $(resolveFile $f)"
|
|
|
|
done
|
|
|
|
if [[ -n $files ]]; then
|
|
|
|
files=':args! '"$files<cr>"
|
|
|
|
fi
|
|
|
|
cmd="$before$files$after"
|
|
|
|
gvim --remote-send "$cmd"
|
2012-03-30 10:33:06 +00:00
|
|
|
if typeset -f postCallVim > /dev/null; then
|
|
|
|
postCallVim
|
|
|
|
fi
|
2012-03-20 12:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
alias v=callvim
|
|
|
|
alias vvsp="callvim -b':vsp'"
|
|
|
|
alias vhsp="callvim -b':sp'"
|
|
|
|
alias vk="callvim -b':wincmd k'"
|
|
|
|
alias vj="callvim -b':wincmd j'"
|
|
|
|
alias vl="callvim -b':wincmd l'"
|
|
|
|
alias vh="callvim -b':wincmd h'"
|