Browse Source

Some fixes

ruby
aeris 4 years ago
parent
commit
208837b582
  1. 4
      lib/ssh-ident.rb
  2. 18
      lib/ssh-ident/agent.rb

4
lib/ssh-ident.rb

@ -3,7 +3,7 @@ require 'open3'
require 'yaml'
module SSHIdent
VERSION = '1.0.0'.freeze
VERSION = '1.0.1'.freeze
PATH = File.join Dir.home, '.ssh'
CONFIG = YAML.load_file File.join PATH, 'identities', 'config.yml'
@ -59,7 +59,7 @@ module SSHIdent
when :ssh
return SSH_REGEX.match(args.first)[:host]
when :scp
args.first(2).each do |a|
args.each do |a|
m = SCP_REGEX.match a
return m[:host] if m
end

18
lib/ssh-ident/agent.rb

@ -14,7 +14,7 @@ module SSHIdent
end
def run(prog, args)
$stderr.puts "\033[1;41m[ #{@name} ]\033[0m #{prog} #{args.join ' '}"
$stderr.puts "\033[1;41m[ #{@name} ]\033[0m #{prog} #{args.join ' '}" unless ENV['SSH_QUIET']
prog = File.join CONFIG['bin_dir'], prog
raise "#{prog}: not such file or directory" unless File.executable? prog
@ -22,7 +22,11 @@ module SSHIdent
config = File.join @path, 'config'
args = ['-F', config] + args if File.exist? config
exec get_env, prog, *args
$stdout.flush
$stderr.flush
cmd = [get_env, prog, *args]
exec *cmd
end
private
@ -32,14 +36,10 @@ module SSHIdent
env = YAML.load_file @env_path
pid = env['SSH_AGENT_PID']
agent = pid.nil? ? nil : Process.getpgid(pid.to_i) rescue nil
if agent
env
else
start
end
else
start
socket = File.exists? env['SSH_AUTH_SOCK']
return env if agent && socket
end
start
end
def get_env(env = nil)

Loading…
Cancel
Save