Sunday, September 6, 2015

Re: au! FileChangedShell

Excerpts from porphyry5's message of 2015-09-06 12:08:18 -0300:
> On Friday, September 4, 2015 at 11:50:56 AM UTC-7, porphyry5 wrote:
> > I put this command in ~/.vimrc.
> > au! FileChangedShell img.dat r img.dat
> > which also contains
> > set autochdir " pwd is always directory of current buffer
> >
> > I hoped to ensure that, if the file img.dat exists in pwd and
> > it is modified by some app other than vim, then vim would read
> > the new img.dat into the current buffer. It does not, nothing
> > happens.
> >
> > v:fcs_reason is unset
> > :if exists("#FileChangedShell") | echo 'yes' | else | echo 'no' | endif
> > returns 'yes'
> >
> > What am I missing?
> >
> > --
> >
> > Graham Lawrence
>
> Thank you both, Marco and Ben Fritz, for your info. I had interpreted FileChangedShell to mean that if I had a buffer for img.dat in vim, I could automatically read its update into another buffer exactly where I want the new data to end up. In other words, completely effortless on my part.
>
> The img.dat buffer is duly updated, but the r command to read it into the active buffer does not operate. Can it be done?
you may use :buffer img.dat

But,

I'm afraid you are using the wrong tool for the job. If what you want is
to watch for a file modification you could use a shell script for it.
Something along these lines:

$cat watch_file.sh

FILE="$1"

TIME=$(ls --full-time $FILE | sed 's/\s\+/ /g' | cut -d ' ' -f 6,7,8)

while : ; do

TEMP=$(ls --full-time $FILE | sed 's/\s\+/ /g' | cut -d ' ' -f 6,7,8)

if [[ $TIME != $TEMP ]] ; then
echo "$FILE Modified";
TIME="$TEMP"
else
# 1 sec delay
sleep 1
fi
done

>
> --

--
Marco Arthur @ (M)arco Creatives

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: