hiraishin 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d6fd25acc2fa0c00472acbac67d3c7b9d849cf4762642b9b7fbda48b516a311d
4
+ data.tar.gz: b4efcf6fc11951fbaf3a6d2fa1acc38bff8108df2bdc4107654e1de4f53c8a5b
5
+ SHA512:
6
+ metadata.gz: 227ee32dfb1513ba7fb4976a84f9f3934a4b549a0908b5cd59ba1b2a8bc5ae82379c7da4499085b61f12a7b70562f832ae73de431716fe54aa3077d9b30a39ed
7
+ data.tar.gz: 93fcb419ae27d18d81b091c80d8088abd4d2a7e9075fbc00e44d70a1a0d3c333332f83980172012d817268ba1cd11eb6997d9a0d372a15d1cee116f11948555e
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ require_relative '../lib/hiraishin'
6
+
7
+ #TODO: Add support for other GUIs
8
+
9
+ Options = Struct.new(:name, :command, :keys)
10
+
11
+ args = Options.new
12
+
13
+ opt_parser = OptionParser.new do |opts|
14
+ opts.banner = "Usage: hiraishin -n NAME -c path/to/command -k keys,to,be,pressed"
15
+
16
+ opts.on("-n NAME", "--name=NAME", "Name of the shortcut") do |n|
17
+ args.name = n
18
+ end
19
+
20
+ opts.on("-c COMMAND", "--command=COMMAND", "Command to be executed") do |c|
21
+ args.command = c
22
+ end
23
+
24
+ opts.on("-k KEYS", "--keys=KEYS", Array, "Keys to bind shortcut to") do |keys|
25
+ args.keys = keys
26
+ end
27
+
28
+ opts.on("-h", "--help", "Prints this help") do
29
+ puts opts
30
+ exit
31
+ end
32
+
33
+ opts.on("") do
34
+ puts opts
35
+ exit
36
+ end
37
+
38
+ end.parse!(ARGV)
39
+
40
+ Hiraishin.add_shortcut_to_cinnamon args.name, args.command, *args.keys
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'hiraishin'
3
+ spec.version = '0.0.1'
4
+ spec.authors = ['Luan Gonçalves Barbosa']
5
+ spec.email = ['luan.goncbs@gmail.com']
6
+ spec.summary = 'A simple gem that adds executable and library for adding shortcuts to programs'
7
+ spec.homepage = 'https://github.com/LuanGB/hiraishin'
8
+ spec.license = 'MIT'
9
+
10
+ spec.files = `git ls-files -z`.split("\x0")
11
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
12
+ spec.require_paths = ['lib']
13
+ end
@@ -0,0 +1,30 @@
1
+ class Hiraishin
2
+
3
+ attr_reader :current_shortcuts
4
+
5
+ def self.add_shortcut_to_cinnamon(name, command, *keys)
6
+ `gsettings set org.cinnamon.desktop.keybindings custom-list "[#{current_shortcuts.join(', ')}, 'custom#{last_shortcode_number}']"`
7
+ `gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom#{last_shortcode_number}/ name "#{name}"`
8
+ `gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom#{last_shortcode_number}/ command "#{command}"`
9
+ `gsettings set org.cinnamon.desktop.keybindings.custom-keybinding:/org/cinnamon/desktop/keybindings/custom-keybindings/custom#{last_shortcode_number}/ binding "['<Primary>#{format_keys(keys)}']"`
10
+
11
+ p "Shortcut #{format_keys(keys)} ('#{name}') created for #{command}"
12
+
13
+ true
14
+ end
15
+
16
+ private
17
+
18
+ def self.format_keys(keys)
19
+ [keys[0..-2].map{ |key| "<#{key}>" }.join, keys[-1].downcase].join
20
+ end
21
+
22
+ def self.current_shortcuts
23
+ @current_shortcuts ||= `gsettings get org.cinnamon.desktop.keybindings custom-list`.chomp[1..-2]&.split(', ')
24
+ end
25
+
26
+ def self.last_shortcode_number
27
+ last_keybinding = current_shortcuts.sort.last
28
+ (last_keybinding[-2].to_i + 1).to_s
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiraishin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luan Gonçalves Barbosa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-14 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - luan.goncbs@gmail.com
16
+ executables:
17
+ - hiraishin
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/hiraishin
22
+ - hiraishin.gemspec
23
+ - lib/hiraishin.rb
24
+ homepage: https://github.com/LuanGB/hiraishin
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.7.6
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: A simple gem that adds executable and library for adding shortcuts to programs
48
+ test_files: []