dtas.git  about / heads / tags
duct tape audio suite for *nix
blob 21c766251d67f23ccad25164970eed03d0024503 1096 bytes (raw)
$ git show tfx-pu:lib/dtas/edit_client.rb	# shows this blob on the CLI

 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
# Copyright (C) 2013-2015 all contributors <dtas-all@nongnu.org>
# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
require 'tempfile'
require 'yaml'
require_relative 'unix_client'
require_relative 'disclaimer'

# common code between dtas-sourceedit and dtas-sinkedit
module DTAS::EditClient # :nodoc:
  def editor
    %w(VISUAL EDITOR).each do |key|
      v = ENV[key] or next
      v.empty? and next
      return v
    end
    "vi"
  end

  def client_socket
    DTAS::UNIXClient.new
  rescue
    e = "DTAS_PLAYER_SOCK=#{DTAS::UNIXClient.default_path}"
    abort "dtas-player not running on #{e}"
  end

  def tmpyaml
    tmp = Tempfile.new(%W(#{File.basename($0)} .yml))
    tmp.sync = true
    tmp.binmode
    tmp
  end

  def update_cmd_env(cmd, orig, updated)
    if env = updated["env"]
      env.each do |k,v|
        cmd << (v.nil? ? "env##{k}" : "env.#{k}=#{v}")
      end
    end

    # remove deleted env
    if orig_env = orig["env"]
      env ||= {}
      deleted_keys = orig_env.keys - env.keys
      deleted_keys.each { |k| cmd << "env##{k}" }
    end
  end
end

git clone git://80x24.org/dtas.git
git clone https://80x24.org/dtas.git