about summary refs log tree commit homepage
path: root/bin/dtas-sourceedit
blob: 3de1c119132aa0884b7af74a980000419c0c1490 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env ruby
# -*- encoding: binary -*-
# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require 'dtas/edit_client'
include DTAS::EditClient
c = client_socket
sources = c.req('source ls') || "(unknown)"
usage = "Usage: #{DTAS_PROGNAME} SOURCENAME\n" \
        "available SOURCENAME values: #{sources}"
ARGV.size <= 1 or abort usage
name = ARGV[0] || "sox"

tmp = tmpyaml
buf = c.req(%W(source cat #{name}))
abort(buf) if buf =~ /\AERR/
orig = YAML.load(buf)

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 #{name})
update_cmd_env(cmd, orig, source)

# nil OK
%w(tryorder command).each do |field|
  cmd << "#{field}=#{source[field]}"
end

c.req_ok(cmd)