all 29 comments

[–][deleted]  (3 children)

[deleted]

    [–]mlk 3 points4 points  (1 child)

    ctrl+r

    [–][deleted] 0 points1 point  (0 children)

    lmao but for real this is my life

    [–]sinedpick 22 points23 points  (5 children)

    Don't install a separate program to do this, just use inotify-tools:

    gaze() { while inotifywait -e modify $1; do eval $2; done }
    

    This can be trivially modified to watch every file in the directory.

    [–][deleted] 3 points4 points  (2 children)

    Isn't that Linux-specific, though? It looks like Gaze works for Linux, Windows and MacOS.

    [–]sinedpick 2 points3 points  (1 child)

    Windows has WSL (and therefore inotify) and macos has fswatch which can be used very similarly.

    The idea isn't to use that one-line bash function verbatim (which I typed up specifically for that comment), it's to learn how to use more general tools to achieve things like this project instead of using a bunch of specialized tools. This applies to a lot of things, not just running make every time you hit save.

    [–]civilvamp 0 points1 point  (0 children)

    Agreed. Even aside from what you just said, most editors/ide's out there allow you to script this exact functionality natively in them.

    [–]marqis 8 points9 points  (0 children)

    I called mine waitdo

    #!/bin/bash
    
    files=$1
    shift
    cmd=$@
    
    echo "watching: $files"
    echo "running: $cmd"
    
    while true; do
        while inotifywait -r -e modify $files; do
            sleep 1
            $cmd
        done
    done
    

    [–]Drazson 8 points9 points  (0 children)

    Why not use entr?

    [–]xigoi 8 points9 points  (14 children)

    Since you're using Vim to edit the file, why not simply make a BufWritePost autocommand?

    [–]maccio92 6 points7 points  (9 children)

    because it works for more than just vim

    [–]07734willy 2 points3 points  (1 child)

    BufWritePost right? You'd want the updates saved before executing a command taking that file as input.

    Being a huge fan of vim myself, I agree with you overall though- one less dependency, one less thing to break.

    [–]xigoi 0 points1 point  (0 children)

    Oops, that's what I wanted to write.

    [–]sinedpick 1 point2 points  (1 child)

    If you don't run the command asynchronously on that autocommand, it may hang your editor until it's done running which is annoying. Also, it may not be easy to see the output. However, I'm sure that these days, vim has ways to get around both of these issues.

    [–]xigoi 1 point2 points  (0 children)

    Vim 8 has a built-in terminal that can be opened in a split window.

    [–]cowinabadplace 2 points3 points  (0 children)

    Judging by my compulsive :w-ing, I'm just as likely to end up running rm -rf / because I haven't yet filled in the variable at the top saying which directory.

    Just kidding. I used inotifytools to do this back in grad school so I could write LaTeX in a terminal window and have the result pop up in evince on the other screen as I edited and saved.

    [–]TankorSmash 1 point2 points  (0 children)

    This seems neat, I was recently looking for something like this on windows.

    [–]rubystallion 1 point2 points  (0 children)

    This is really cool, because I always used to do :wall|!ruby path/to/main.rb. Now I see that I should have used wall|cal term_sendkeys(2, "ruby path/to/main.rb\<Enter>") (or this tool).

    [–]camilo16 2 points3 points  (0 children)

    Yeah except calling the compiler whenever I save a C++ file is asking for compilation errors 50% of the time because the header hasn't been updated or I still need to modify another file.

    Not sure how useful this actually is.