-
-
Save foca/804035 to your computer and use it in GitHub Desktop.
Wrapper for synergy to ease the pain of configuring/running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
def ps(command, command_size=3) | |
capture = (5...5+command_size).map {|c| "$#{c}" }.join(' " " ') | |
%Q(ps x | grep #{command} | grep -v 'grep #{command}' | awk '{ print #{capture} }') | |
end | |
def ssh(server, command) | |
%Q(ssh #{server} #{command}) | |
end | |
def run(command) | |
$stderr.puts command if $debug | |
system command | |
end | |
hostname = `hostname` | |
$debug = ARGV.detect {|arg| arg == "-d" } | |
foreground = ARGV.detect {|arg| arg == "-f" } | |
args = ARGV.reject {|arg| arg =~ /^-/ } | |
case args.first | |
when "start", nil | |
run "synergys #{foreground} --config ~/.synergy/config" | |
when "remote" | |
abort "You need to provide an ssh host" unless args[1] | |
run ssh(args[1], "synergyc #{foreground} #{hostname}") | |
when "status" | |
run ps("synergys") | |
run ssh(args[1], ps("synergyc", 2)) if args[1] | |
when "stop" | |
run "killall synergys" | |
when "use" | |
run "ln -nfs ~/.synergy/#{args[1]}.conf ~/.synergy/config" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment