开发工具 写个小脚本帮助调试 Ruby 或者 Shell 脚本

gene_wu · August 24, 2013 · 3192 hits

受到https://gist.github.com/derekwyatt/3577440Ruby的启发,碰到平时如果只需要写一个脚本,或者一个简单 Code 的时候,这个 Script 可以监视文件的修改,执行固定的命令。

#!/bin/bash

# watchdoit "ruby" .rb

command="$1"
shift
fileSpec="$@"
sentinel=/tmp/t.$$

touch -t197001010000 $sentinel
while :
do
  files=$(find . -newer $sentinel -a '(' -name "*$fileSpec" ')')
  if [ $? != 0 ]; then
    exit 1;
  fi
  if [ "$files" != "" ]; then
    $command $files
    touch $sentinel
  fi
  sleep 0.5 
done

https://gist.github.com/genewoo/6321290

PS,本人 VIM+Tmux 党,这个比较方便分屏调试单一脚本。

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.