au! FileChangedShell

34 views
Skip to first unread message

Graham Lawrence

unread,
Sep 4, 2015, 2:50:56 PM9/4/15
to vim...@googlegroups.com

	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

Marco

unread,
Sep 4, 2015, 3:44:31 PM9/4/15
to vim_use
Excerpts from Graham Lawrence's message of 2015-09-04 15:50:47 -0300:
> 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

FileChangedShell is triggered mostly after executing a shell command
(:!) check :he FileChangedShell


--
Marco Arthur @ (M)arco Creatives

Ben Fritz

unread,
Sep 4, 2015, 3:47:46 PM9/4/15
to vim_use
On Friday, September 4, 2015 at 2:44:31 PM UTC-5, Marco wrote:
> Excerpts from Graham Lawrence's message of 2015-09-04 15:50:47 -0300:
> > 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
>
> FileChangedShell is triggered mostly after executing a shell command
> (:!) check :he FileChangedShell
>

It also only fires if you're currently editing a buffer for that file. You can't monitor arbitrary files which are not open in Vim using that autocmd, which seems to be what you're trying to do for some reason.

porphyry5

unread,
Sep 6, 2015, 11:08:18 AM9/6/15
to vim_use

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?

Marco

unread,
Sep 6, 2015, 2:00:11 PM9/6/15
to vim_use
Excerpts from porphyry5's message of 2015-09-06 12:08:18 -0300:
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

>
> --

Christian Brabandt

unread,
Sep 6, 2015, 3:42:27 PM9/6/15
to vim_use
Hi Marco!

On So, 06 Sep 2015, Marco wrote:

> $cat watch_file.sh
>
> FILE="$1"
>
> TIME=$(ls --full-time $FILE | sed 's/\s\+/ /g' | cut -d ' ' -f 6,7,8)
>
> while : ; do
...
> sleep 1

I think, inotify would be prefered.

Best,
Christian
--
Freiheit nur für die Anhänger der Regierung, nur für die Mitglieder
einer Partei ist keine Freiheit. Freiheit ist immer nur Freiheit des
anders Denkenden.
-- Rosa Luxemburg
Reply all
Reply to author
Forward
0 new messages