From 3e09ac0c10c95bb24a08af62393b4f761e2743d0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 24 Aug 2013 09:54:45 +0000 Subject: initial commit --- bin/dtas-sourceedit | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 bin/dtas-sourceedit (limited to 'bin/dtas-sourceedit') 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 +# 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) -- cgit v1.2.3-24-ge0c7