diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-08-24 09:54:45 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-08-24 09:54:45 +0000 |
commit | 3e09ac0c10c95bb24a08af62393b4f761e2743d0 (patch) | |
tree | 778dffa2ba8798503fc047db0feef6d65426ea22 /bin/dtas-sourceedit | |
download | dtas-3e09ac0c10c95bb24a08af62393b4f761e2743d0.tar.gz |
Diffstat (limited to 'bin/dtas-sourceedit')
-rwxr-xr-x | bin/dtas-sourceedit | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/bin/dtas-sourceedit b/bin/dtas-sourceedit new file mode 100755 index 0000000..9d329d7 --- /dev/null +++ b/bin/dtas-sourceedit @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby +# -*- encoding: binary -*- +# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require 'tempfile' +require 'yaml' +require 'dtas/unix_client' +require 'dtas/disclaimer' +editor = ENV["VISUAL"] || ENV["EDITOR"] +c = DTAS::UNIXClient.new +usage = $0 +ARGV.size == 0 or abort usage +name = ARGV[0] + +tmp = Tempfile.new(%w(dtas-sourceedit .yml)) +tmp.sync = true +tmp.binmode + +buf = c.req(%W(source cat)) +abort(buf) if buf =~ /\AERR/ + +tmp.write(buf << DTAS_DISCLAIMER) +cmd = "#{editor} #{tmp.path}" +system(cmd) or abort "#{cmd} failed: #$?" +tmp.rewind +source = YAML.load(tmp.read) + +cmd = %W(source ed) +if env = source["env"] + env.each do |k,v| + cmd << (v.nil? ? "env##{k}" : "env.#{k}=#{v}") + end +end + +%w(command).each do |field| + value = source[field] and cmd << "#{field}=#{value}" +end + +c.req_ok(cmd) |