Mirmo Dynamics

Si tu kiffes pas reunoi, t'écoutes pas et puis c'est tout.

To content | To menu | To search

Keyword - bash

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

Thursday 10 July 2008

Rename directories to lowercase

Using a single (and somewhat simple) shell line, you can rename any directory to its lowercase version.

for i in *; do lcase=`echo $i | tr A-Z a-z`; if [ ! -d $lcase ]; then mv $i $lcase; fi; done;

Viva el chell !