[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[eev] My zsh functions for e-scripts
From: |
rubikitch |
Subject: |
[eev] My zsh functions for e-scripts |
Date: |
Tue, 17 Jan 2006 05:15:33 +0900 (JST) |
Hi,
# (find-w3m "http://lists.gnu.org/archive/html/eev/2006-01/msg00001.html")
# (find-w3m "http://lists.gnu.org/archive/html/eev/2006-01/msg00002.html")
# (find-w3m "http://lists.gnu.org/archive/html/eev/2006-01/msg00000.html")
In addition to these stuffs, my e-scripts contain the following functions.
`result' hilights stdin.
`result-long' does `view-file' stdin.
`assert_*' check value whether it is valid.
This name is borrowed from xUnit, the unit-test framework.
`eegcc2' is extended `eegcc'.
`v' does `view-file' and `e' does `find-file'.
`show-examples' creates temporary e-script to process multiple files.
`replace-string' simply replaces string from stdin.
#
<<'%%%' > $EEVTMPDIR/bell-result.rb
begin
require 'bell'
rescue LoadError
end
class NullOut
def puts(*args)
end
end
$bellout = $bell || NullOut.new
def result(input)
input = input.read if input.respond_to? :read
puts "\e[32m#{input}\e[0m"
$bellout.puts "\e[32m*result*\e[0m\n#{input}"
end
def sh_assert_equal
expected, msg = ARGV
actual = STDIN.read.chomp
puts actual
msg ||= "AssertEqual"
msg << ": "
if expected == actual
msg << "ok\n"
else
msg << "EXPECTED <#{expected}> BUT WAS <#{actual}>\n"
end
result msg
end
def sh_assert_match
regexps = ARGV.map{|x| Regexp.new(x) }
input = STDIN.read.chomp
puts input
msg = ""
failed = false
regexps.each do |re|
unless input =~ re
failed = true
msg << "AssertMatch: FAILED #{re.inspect}\n"
end
end
msg << "AssertMatch: ok\n" unless failed
result msg
end
def sh_assert_no_match
regexps = ARGV.map{|x| Regexp.new(x) }
input = STDIN.read.chomp
puts input
msg = ""
failed = false
regexps.each do |re|
if input =~ re
failed = true
msg << "AssertNoMatch: MATCHED #{re.inspect}\n"
end
end
msg << "AssertNoMatch: ok\n" unless failed
result msg
end
%%%
function result () {
ruby -I $EEVTMPDIR -rbell-result -e 'result(ARGF)'
}
function result-long () {
res=$EEVTMPDIR/result.txt
cat > $res
v $res
}
#
# assertions
function assert_equal () {
ruby -I $EEVTMPDIR -r bell-result -e sh_assert_equal "$@"
}
function assert_match () {
ruby -I $EEVTMPDIR -r bell-result -e sh_assert_match "$@"
}
function assert_no_match () {
ruby -I $EEVTMPDIR -r bell-result -e sh_assert_no_match "$@"
}
function assert_not_match () {
assert_no_match "$@"
}
function assert_same_file () {
if cmp $1 $2 > /dev/null; then
echo 'AssertSameFile: ok' | result
else
echo 'AssertSameFile: DIFFER' | result
diff -u $1 $2
fi
}
#
function eegcc2 () {
cat $EETMPC - > $EEC
gcc -o $EEAOUT $*
}
#
# view-file
function v () {
gnuclient --batch --eval "(let ((default-directory \"$(pwd)\")) (view-file
\"$1\"))"
}
function e () {
gnuclient --batch --eval "(let ((default-directory \"$(pwd)\")) (find-file
\"$1\"))"
}
# (eevnow "v ~/.emacs")
#
doit () { echo $* }
#
# show-examples
# `doit' for multiple files
show-examples () {
for file in "$@"; do
echo "doit $file"
done | result-long
}
#
replace-string () {
ruby -e 're=Regexp.new(Regexp.quote(ARGV[0])); repl = ARGV[1];
$stdin.read.gsub(re,repl).display' "$@"
}
--
rubikitch
http://www.rubyist.net/~rubikitch/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [eev] My zsh functions for e-scripts,
rubikitch <=