2013-10-27 98 views
1

我正在创建一个命令行lint工具来在Linux上运行。创建一个aspell样式的文件编辑bash脚本

我的输出目前是这样的:

./ex4/task6.7/SumOfCubedDigits.java 
> Line 15 has inconsistent indenting 
> Line 16 has inconsistent indenting 
./ex2/task3.2/YearsBeforeRetirement.java 
> Line 0 has a curly brace on the end 
./ex2/task3.4/YearsBeforeRetirement.java 
> Line 0 has a curly brace on the end 
./ex2/task3.7/ThreeWeights.java 
> Line 18 has inconsistent indenting 
> Line 29 has inconsistent indenting 
./ex2/task3.7/fourWeightsCoffeeTime/FourWeights.java 
> Line 9 has inconsistent indenting 
> Line 11 has inconsistent indenting 
./ex2/task2.9/Limerick.java 
> Line 0 has a curly brace on the end 

通过输出管道进入awk '/.\/ex/{print;}'我可以只提取文件名:

./ex4/task6.7/SumOfCubedDigits.java 
./ex2/task3.2/YearsBeforeRetirement.java 
./ex2/task3.4/YearsBeforeRetirement.java 
./ex2/task3.7/ThreeWeights.java 
./ex2/task3.7/fourWeightsCoffeeTime/FourWeights.java 
./ex2/task2.9/Limerick.java 

我想打开每个反过来这些文件并编辑它们,也许给每个文件中的错误提供一条消息给用户,因为我打开它们。类似于aspell所做的。

这可能吗?

+0

你为什么不从_within_ emacs的执行命令? – devnull

+0

我不使用emacs:/ –

回答

0

你可以尝试以下bash脚本:

files=$(awk '/.\/ex/{print;}' input.txt) 
for file in $files ; do 
    echo "File: "$file 
    echo "Errors:" 
    awk -vfile=$file -f getErr.awk input.txt 
    #open file in editor 
done 

其中input.txt是从lint命令的输出,并getErr.awk

$0 ~ file {f=1; next} 
f && /^> Line/ {print;next} 
{f=0} 
1

随着

演示:

enter image description here

代码:

file=/path/to/file.txt 

trap '\rm -f /tmp/out_file' 0 1 2 3 15 

if dialog \ 
    --clear \ 
    --title "Pick up one of these files" \ 
    --menu "Files/errors" 80 300 100 $(
     awk '/>/{ 
      $1="" 
      gsub(/ +/, "_", $0) 
      arr[k]=arr[k] $0 
      next 
     } 
     {k=$0} 
     END{for (a in arr) printf "%s ", a " " arr[a]} 
    ' "$file") 2>/tmp/out_file 
then 
    $EDITOR "$(</tmp/out_file)" 
fi