\_o< ~ Mirmo Dynamics

Rien de grand ne se fit jamais sans enthousiasme.

To content | To menu | To search

Keyword - script

Entries feed - Comments feed

Thursday 16 October 2008

Mass vim file opening reloaded

Thinking about it, the snippet I posted earlier was a bit silly as vim can open by itself multiple files way more efficiently. The only benefit from my script is that I don't have to type the --servername and --remote-silent-tab.

So let's add some usefulness ! First, when I need this script, it's often that I first grepped the files, and then decide that I want to edit them all. From this point of view, having to pass them as arguments is not that handy, so we'll add a way to pass them via STDIN.

Also, what if I want to send them to another vim server ? We'll add this ability too.

Here is the resulting script:

#!/usr/bin/env bash

# set a default SERVERNAME
SERVERNAME="ash0"

# look for files on stdin
if ! [ -t 0 ]; then
  FILES=`cat /dev/stdin`
else
  exit;
fi;

# now let's check if we want a specific vim server
if ! [ -z $1 ]; then
  SERVERNAME=$1
fi;

# we can now open the files
/usr/bin/gvim --servername $SERVERNAME --remote-silent-tab $FILES

Tada !

You can now do the followings:

grep foo | sendtovim
grep foo | sendtovim grep0

Tuesday 14 October 2008

Mass vim file opening

Remember my old post about vim and rox-filer ? Well I've got one tiny and silly addition to it now, I can mass open files from any shell command line, with this little script placed in my ~/bin/ (don't forget to chmod +x):

for i in $*; do
  /usr/bin/gvim --servername ash0 --remote-silent-tab $i
  sleep 1
done;

The sleep 1 is necessary as vim does not seem to like being flooded with files.

Example usage:

sendtovim `grep foo *`

Opens in vim all files containing "foo" in the current directory. Who said handy ?

Note: I know have an updated and useful version of this script