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

gene_wu · 2013年08月24日 · 3191 次阅读

受到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 党,这个比较方便分屏调试单一脚本。

暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号