snippet_cli 0.1.4

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0156a7f915100439d250fa9514c043cba1cbc21a2a6a60288f408b90e3776a59
4
+ data.tar.gz: 53e5c2a6837653425b37c3483f27e059b2a5b98b9a42a1ab4108c932196a289a
5
+ SHA512:
6
+ metadata.gz: 55052c998225ab4aa759979e6c8372d80702b9b8a951187d212ad4da91c7be714fc6fd9d2a56e959671a0fc08c60849c96d6ef64cd6f2100ac314859b3cf0008
7
+ data.tar.gz: 8acefc771c8771a1d0471eefd1aefa10516d0101f6fca781da985f09ede2612ba132592f79c50ac451a7b3b40055c146ce5c6fdf4e2214f639ac8f13e2ca617a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alexanderjmarkow@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in snippet_cli.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "tty-prompt"
9
+ gem "tty-box"
10
+ gem "tty-platform"
11
+ gem 'tty-markdown'
12
+ gem "pastel"
13
+ gem "bundler"
14
+ gem "snippets_for_espanso"
15
+ gem "httparty"
16
+ gem "ascii"
data/Gemfile.lock ADDED
@@ -0,0 +1,90 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ snippet_cli (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ascii (1.0.1)
10
+ diff-lcs (1.4.4)
11
+ httparty (0.18.1)
12
+ mime-types (~> 3.0)
13
+ multi_xml (>= 0.5.2)
14
+ kramdown (2.3.0)
15
+ rexml
16
+ mime-types (3.3.1)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2020.1104)
19
+ multi_xml (0.6.0)
20
+ pastel (0.8.0)
21
+ tty-color (~> 0.5)
22
+ rake (12.3.3)
23
+ rexml (3.2.4)
24
+ rouge (3.26.0)
25
+ rspec (3.10.0)
26
+ rspec-core (~> 3.10.0)
27
+ rspec-expectations (~> 3.10.0)
28
+ rspec-mocks (~> 3.10.0)
29
+ rspec-core (3.10.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-expectations (3.10.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-mocks (3.10.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-support (3.10.0)
38
+ snippets_for_espanso (0.1.2)
39
+ yaml
40
+ strings (0.2.0)
41
+ strings-ansi (~> 0.2)
42
+ unicode-display_width (~> 1.5)
43
+ unicode_utils (~> 1.4)
44
+ strings-ansi (0.2.0)
45
+ tty-box (0.7.0)
46
+ pastel (~> 0.8)
47
+ strings (~> 0.2.0)
48
+ tty-cursor (~> 0.7)
49
+ tty-color (0.6.0)
50
+ tty-cursor (0.7.1)
51
+ tty-markdown (0.7.0)
52
+ kramdown (>= 1.16.2, < 3.0)
53
+ pastel (~> 0.8)
54
+ rouge (~> 3.14)
55
+ strings (~> 0.2.0)
56
+ tty-color (~> 0.5)
57
+ tty-screen (~> 0.8)
58
+ tty-platform (0.3.0)
59
+ tty-prompt (0.23.0)
60
+ pastel (~> 0.8)
61
+ tty-reader (~> 0.8)
62
+ tty-reader (0.9.0)
63
+ tty-cursor (~> 0.7)
64
+ tty-screen (~> 0.8)
65
+ wisper (~> 2.0)
66
+ tty-screen (0.8.1)
67
+ unicode-display_width (1.7.0)
68
+ unicode_utils (1.4.0)
69
+ wisper (2.0.1)
70
+ yaml (0.1.0)
71
+
72
+ PLATFORMS
73
+ x64-mingw32
74
+
75
+ DEPENDENCIES
76
+ ascii
77
+ bundler
78
+ httparty
79
+ pastel
80
+ rake (~> 12.0)
81
+ rspec (~> 3.0)
82
+ snippet_cli!
83
+ snippets_for_espanso
84
+ tty-box
85
+ tty-markdown
86
+ tty-platform
87
+ tty-prompt
88
+
89
+ BUNDLED WITH
90
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 AJ Markow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # SnippetCli
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/snippet_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'snippet_cli'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install snippet_cli
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/snippet_cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/snippet_cli/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## Code of Conduct
39
+
40
+ Everyone interacting in the SnippetCli project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/snippet_cli/blob/master/CODE_OF_CONDUCT.md).
41
+
42
+ ## Copyright
43
+
44
+ Copyright (c) 2020 AJ Markow. See [MIT License](LICENSE.txt) for further details.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "snippet_cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/snippet_cli ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib_path = File.expand_path('../lib', __dir__)
5
+ $:.unshift(lib_path) if !$:.include?(lib_path)
6
+ require 'snippet_cli/cli'
7
+
8
+ Signal.trap('INT') do
9
+ warn("\n#{caller.join("\n")}: interrupted")
10
+ exit(1)
11
+ end
12
+
13
+ begin
14
+ SnippetCli::CLI.start
15
+ rescue SnippetCli::CLI::Error => err
16
+ puts "ERROR: #{err.message}"
17
+ exit 1
18
+ end
data/lib/Setup.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'tty/prompt'
2
+ require 'tty/box'
3
+ prompt = TTY::Prompt.new
4
+
5
+
6
+ class Setup
7
+ @leading = " "
8
+ @divider = "------------------------------------"
9
+ attr_accessor :user_name,:user_os,:user_storage,:config_present
10
+
11
+ def initialize(user_name,user_os,user_storage,config_present)
12
+ @user_name = user_name
13
+ @user_os = user_os
14
+ @user_storage = user_storage
15
+ @config_present = config_present
16
+ end
17
+
18
+ class Error < StandardError; end
19
+
20
+
21
+ def get_name()
22
+ puts @leading
23
+ prompt = TTY::Prompt.new
24
+ name = prompt.ask("To begin setup, may I have your name?", default: ENV["USER"], active_color: :bright_blue) do |q|
25
+ q.required true
26
+ end
27
+ puts @leading
28
+ self.user_name = name
29
+ end
30
+
31
+ def get_os()
32
+ puts @leading
33
+ prompt = TTY::Prompt.new
34
+ config_path = prompt.ask("What OS are you using?", default: ENV["OS"], active_color: :bright_blue) do |q|
35
+ q.required true
36
+ end
37
+ if (config_path.include? "Windows")
38
+ return config_path = "\\Roaming\\AppData\\espanso\\default.yml"
39
+ elsif (config_path.include?"OS X")
40
+ return config_path = "$HOME/Library/Preferences/espanso/default.yml"
41
+ else config_path.include?("Linux")
42
+ return config_path = "$XDG_CONFIG_HOME/espanso/default.yml"
43
+ end
44
+ puts @leading
45
+ self.user_os=config_path
46
+ end
47
+
48
+ # REFACTOR TO PROVIDE PATH
49
+ def get_storage()
50
+ puts @leading
51
+ prompt = TTY::Prompt.new
52
+ return snippet_storage = prompt.select("Do your store your snippets in Dropbox or a different directory?", default: 1, active_color: :bright_blue) do |menu|
53
+ menu.enum "."
54
+
55
+ menu.choice "No I use the default folder.", 1
56
+ menu.choice "I use Dropbox.", 2
57
+ menu.choice "I use Google Drive", 3
58
+ menu.choice "I use Another Directory.", 4
59
+ end
60
+ puts @leading
61
+ self.user_storage = snippet_storage
62
+ end
63
+
64
+ def generate_config()
65
+ if File.exist?("./snippet_cli_config.txt") then
66
+
67
+ else
68
+ File.open("./snippet_cli_config.txt", "a") { |f| f.write "NAME = #{self.user_name}\n"}
69
+ File.open("./snippet_cli_config.txt", "a") { |f| f.write "OS = #{self.user_os}\n"}
70
+ File.open("./snippet_cli_config.txt", "a") { |f| f.write "STORAGE = #{self.user_storage}\n"}
71
+ File.open("./snippet_cli_config.txt", "a") { |f| f.write "CONFIG_PRESENT = TRUE\n"}
72
+ end
73
+ end
74
+ end
data/lib/banner.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'tty-box'
2
+
3
+ def show_banner()
4
+ box = TTY::Box::frame(width:67, height:11, border: :thick, align: :left) do
5
+ "
6
+ ##### # # ### ###### ###### ####### #######
7
+ # # ## # # # # # # # #
8
+ # # # # # # # # # # #
9
+ ##### # # # # ###### ###### ##### #
10
+ # # # # # # # # #
11
+ # # # ## # # # # #
12
+ ##### # # ### # # ####### # CLI
13
+ "
14
+ end
15
+ puts box
16
+ end
data/lib/info.md ADDED
@@ -0,0 +1,20 @@
1
+ # Thanks for trying Snippet CLI!
2
+
3
+ Hi! Have any feedback?
4
+ We'd love to hear it.
5
+ Click the link below to send an email to the developer.
6
+
7
+ ## Links
8
+
9
+ - [Install Espanso](https://espanso.org/)
10
+ - [Snippet CLI Github](https://www.github.com/ajmarkow/snippet_cli)
11
+ - [Snippet CLI Docs](https:/docs.snippetcli.com)
12
+ - [Email Me Feedback](mailto:aj@ajm.codes)
13
+
14
+ ## Commands
15
+
16
+ | **Command** | **Purpose** |
17
+ |----------|:------------------:|
18
+ | setup | Sets up path to snippet file |
19
+ | new | Opens dialog to add new snippet or form. |
20
+ | info| Docs, Contact Info, and Resources |
@@ -0,0 +1,4 @@
1
+ require "snippet_cli/version"
2
+
3
+ module SnippetCli
4
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module SnippetCli
6
+ # Handle the application command line parsing
7
+ # and the dispatch to various command objects
8
+ #
9
+ # @api public
10
+ class CLI < Thor
11
+ # Error raised by this runner
12
+ Error = Class.new(StandardError)
13
+
14
+ desc 'version', 'snippet_cli version'
15
+ def version
16
+ require_relative 'version'
17
+ puts "v#{SnippetCli::VERSION}"
18
+ end
19
+ map %w(--version -v) => :version
20
+
21
+ desc 'info [DOCS]', 'Show info and docs about using the program.'
22
+ method_option :help, aliases: '-h', type: :boolean,
23
+ desc: 'Display usage information'
24
+ def info(docs = nil)
25
+ if options[:help]
26
+ invoke :help, ['info']
27
+ else
28
+ require_relative 'commands/info'
29
+ SnippetCli::Commands::Info.new(docs, options).execute
30
+ end
31
+ end
32
+
33
+ desc 'new', 'Guides you through adding a new snippet.'
34
+ method_option :help, aliases: '-h', type: :boolean,
35
+ desc: 'Display usage information'
36
+ def new(*)
37
+ if options[:help]
38
+ invoke :help, ['new']
39
+ else
40
+ require_relative 'commands/new'
41
+ SnippetCli::Commands::New.new(options).execute
42
+ end
43
+ end
44
+
45
+ desc 'setup', 'Sets up snippet_cli to modify correct.'
46
+ method_option :help, aliases: '-h', type: :boolean,
47
+ desc: 'Set directory to write to snippet file in'
48
+ def setup(*)
49
+ if options[:help]
50
+ invoke :help, ['setup']
51
+ else
52
+ require_relative 'commands/setup'
53
+ SnippetCli::Commands::Setup.new().execute
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module SnippetCli
6
+ class Command
7
+ extend Forwardable
8
+
9
+ def_delegators :command, :run
10
+
11
+ # Execute this command
12
+ #
13
+ # @api public
14
+ def execute(*)
15
+ raise(
16
+ NotImplementedError,
17
+ "#{self.class}##{__method__} must be implemented"
18
+ )
19
+ end
20
+
21
+ # The external commands runner
22
+ #
23
+ # @see http://www.rubydoc.info/gems/tty-command
24
+ #
25
+ # @api public
26
+ def command(**options)
27
+ require 'tty-command'
28
+ TTY::Command.new(options)
29
+ end
30
+
31
+ # The cursor movement
32
+ #
33
+ # @see http://www.rubydoc.info/gems/tty-cursor
34
+ #
35
+ # @api public
36
+ def cursor
37
+ require 'tty-cursor'
38
+ TTY::Cursor
39
+ end
40
+
41
+ # Open a file or text in the user's preferred editor
42
+ #
43
+ # @see http://www.rubydoc.info/gems/tty-editor
44
+ #
45
+ # @api public
46
+ def editor
47
+ require 'tty-editor'
48
+ TTY::Editor
49
+ end
50
+
51
+ # File manipulation utility methods
52
+ #
53
+ # @see http://www.rubydoc.info/gems/tty-file
54
+ #
55
+ # @api public
56
+ def generator
57
+ require 'tty-file'
58
+ TTY::File
59
+ end
60
+
61
+ # Terminal output paging
62
+ #
63
+ # @see http://www.rubydoc.info/gems/tty-pager
64
+ #
65
+ # @api public
66
+ def pager(**options)
67
+ require 'tty-pager'
68
+ TTY::Pager.new(options)
69
+ end
70
+
71
+ # Terminal platform and OS properties
72
+ #
73
+ # @see http://www.rubydoc.info/gems/tty-pager
74
+ #
75
+ # @api public
76
+ def platform
77
+ require 'tty-platform'
78
+ TTY::Platform.new
79
+ end
80
+
81
+ # The interactive prompt
82
+ #
83
+ # @see http://www.rubydoc.info/gems/tty-prompt
84
+ #
85
+ # @api public
86
+ def prompt(**options)
87
+ require 'tty-prompt'
88
+ TTY::Prompt.new(options)
89
+ end
90
+
91
+ # Get terminal screen properties
92
+ #
93
+ # @see http://www.rubydoc.info/gems/tty-screen
94
+ #
95
+ # @api public
96
+ def screen
97
+ require 'tty-screen'
98
+ TTY::Screen
99
+ end
100
+
101
+ # The unix which utility
102
+ #
103
+ # @see http://www.rubydoc.info/gems/tty-which
104
+ #
105
+ # @api public
106
+ def which(*args)
107
+ require 'tty-which'
108
+ TTY::Which.which(*args)
109
+ end
110
+
111
+ # Check if executable exists
112
+ #
113
+ # @see http://www.rubydoc.info/gems/tty-which
114
+ #
115
+ # @api public
116
+ def exec_exist?(*args)
117
+ require 'tty-which'
118
+ TTY::Which.exist?(*args)
119
+ end
120
+ end
121
+ end
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../command'
4
+ require 'tty-markdown'
5
+ require 'tty-box'
6
+
7
+ module SnippetCli
8
+ module Commands
9
+ class Info < SnippetCli::Command
10
+ def initialize(docs, options)
11
+ @docs = docs
12
+ @options = options
13
+ end
14
+
15
+ def execute(input: $stdin, output: $stdout)
16
+ def show_banner()
17
+ box = TTY::Box::frame(width:67, height:11, border: :thick, align: :left) do
18
+ "
19
+ ##### # # ### ###### ###### ####### #######
20
+ # # ## # # # # # # # #
21
+ # # # # # # # # # # #
22
+ ##### # # # # ###### ###### ##### #
23
+ # # # # # # # # #
24
+ # # # ## # # # # #
25
+ ##### # # ### # # ####### # CLI
26
+ "
27
+ end
28
+ puts box
29
+ end
30
+ puts show_banner()
31
+ parsed_markdown=TTY::Markdown.parse_file('./lib/info.md')
32
+ output.puts parsed_markdown
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+ require 'tty-box'
3
+ require 'tty-prompt'
4
+ require 'snippet_generator'
5
+ require 'httparty'
6
+ require 'json'
7
+ require 'ascii'
8
+ # require 'snippets_for_espanso/SnippetGenerator'
9
+ require_relative '../command'
10
+
11
+
12
+ module SnippetCli
13
+ module Commands
14
+ class New < SnippetCli::Command
15
+ def show_banner()
16
+ box = TTY::Box::frame(width:67, height:11, border: :thick, align: :left) do
17
+ "
18
+ ##### # # ### ###### ###### ####### #######
19
+ # # ## # # # # # # # #
20
+ # # # # # # # # # # #
21
+ ##### # # # # ###### ###### ##### #
22
+ # # # # # # # # #
23
+ # # # ## # # # # #
24
+ ##### # # ### # # ####### # CLI
25
+ "
26
+ end
27
+ puts box
28
+ end
29
+ include SnippetGenerator
30
+ @leading = " "
31
+
32
+ prompt=TTY::Prompt.new
33
+ def initialize(options)
34
+ @options = options
35
+ @file_path = File.readlines("#{ENV["HOMEPATH"]}/snippet_cli_config.txt")[1]
36
+ @file_path = Ascii.process(@file_path)
37
+ end
38
+
39
+ def but_first()
40
+ puts @leading
41
+ puts "Now you'll enter what you want replaced."
42
+ puts @leading
43
+ puts "But first ..."
44
+ puts @leading
45
+ prompt.error("Don't use tabs. YAML hates them and it leads to unpredictable results.")
46
+ puts @leading
47
+ end
48
+
49
+ def new_form()
50
+ puts "Let's add a new snippet to your configuration"
51
+ puts @leading
52
+ snippet_type = prompt.select("Do you want a Snippet or a Snippet with a form?") do |menu|
53
+ menu.enum "."
54
+
55
+ menu.choice "A snippet",1
56
+ menu.choice "A snippet with a form",2
57
+ menu.choice "A snippet from Semplificato API",3
58
+ end
59
+ case snippet_type
60
+ when 1
61
+ puts @leading
62
+ snippet_trigger=prompt.ask("What do you want to type to trigger the snippet?")
63
+ puts @leading
64
+ puts "Okay, the snippet will be triggered by:"
65
+ prompt.ok( ":#{snippet_trigger}")
66
+ puts@leading
67
+ but_first()
68
+ replacement = prompt.multiline("what did you want the trigger to be replaced with?")
69
+ if (replacement.length() > 1)
70
+ single_snippet_export(@file_path,snippet_trigger,replacement)
71
+ else
72
+ single_snippet_export(@file_path,snippet_trigger,replacement[0])
73
+ end
74
+ when 2
75
+ puts @leading
76
+ snippet_trigger=prompt.ask("What do you want to type to trigger the snippet?")
77
+ puts @leading
78
+ puts "Okay, the snippet will be triggered by:"
79
+ prompt.ok( ":#{snippet_trigger}")
80
+ puts@leading
81
+ but_first()
82
+ newprompt = TTY::Prompt.new
83
+ newprompt.warn("For a form field wrap the word in double brackets. Like {{example}}")
84
+ puts @leading
85
+ newprompt.ok("Also make sure the name of each form field is unique.")
86
+ puts @leading
87
+ replacement = prompt.multiline("what did you want the trigger to be replaced with?")
88
+ if (replacement.length() > 1)
89
+ input_form_snippet_export(@file_path,snippet_trigger,replacement)
90
+ else
91
+ input_form_snippet_export(@file_path,snippet_trigger,replacement[0])
92
+ end
93
+ when 3
94
+ puts @leading
95
+ url = prompt.ask("What's the URL of the snippet?",default: "http://localhost:3000/snippets/1")
96
+ json_url = url+(".json")
97
+ api_response=HTTParty.get(json_url)
98
+ response_parsed = api_response.body
99
+ single_snippet_export(@file_path,response_parsed['trigger'],response_parsed['replacement'])
100
+ puts@leading
101
+ prompt.ok("Added snippet from #{url}")
102
+ end
103
+ end
104
+
105
+ def execute(input: $stdin, output: $stdout)
106
+ # Command logic goes here ...
107
+ output.puts show_banner()
108
+ new_form()
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,107 @@
1
+ require_relative '../command'
2
+ require 'tty-box'
3
+ require 'tty-prompt'
4
+ require 'tty-platform'
5
+ # frozen_string_literal: true
6
+
7
+
8
+ module SnippetCli
9
+ module Commands
10
+ class Setup < SnippetCli::Command
11
+ platform= TTY::Platform.new
12
+ @leading = " "
13
+ attr_accessor :user_name,:config_path,:user_storage,:config_present,:os_choice
14
+
15
+ def initialize()
16
+ @user_name = user_name
17
+ @config_path = config_path
18
+ @user_storage = user_storage
19
+ @os_choice = os_choice
20
+ @config_present = config_present
21
+ end
22
+
23
+ def show_banner()
24
+ box = TTY::Box::frame(width:67, height:11, border: :thick, align: :left) do
25
+ "
26
+ ##### # # ### ###### ###### ####### #######
27
+ # # ## # # # # # # # #
28
+ # # # # # # # # # # #
29
+ ##### # # # # ###### ###### ##### #
30
+ # # # # # # # # #
31
+ # # # ## # # # # #
32
+ ##### # # ### # # ####### # CLI
33
+ "
34
+ end
35
+ puts box
36
+ end
37
+
38
+ def get_name()
39
+ puts @leading
40
+ prompt = TTY::Prompt.new
41
+ name = prompt.ask("⟶ To begin setup, may I have your name?", default: ENV["USER"], active_color: :bright_blue) do |q|
42
+ q.required true
43
+ end
44
+ puts @leading
45
+ self.user_name = name
46
+ end
47
+
48
+ def get_os()
49
+ puts @leading
50
+ puts "Checking what os you're using..."
51
+ os_choice = platform.os()
52
+ if (platform.windows? == true)
53
+ config_path = "#{ENV["HOMEPATH"]}\\AppData\\Roaming\\espanso\\default.yml"
54
+ elsif (platform.mac? == true)
55
+ config_path = "#{ENV["HOME"]}/Library/Preferences/espanso/default.yml"
56
+ else (platform.linux? == true)
57
+ config_path = "#{ENV["XDG_CONFIG_HOME"]}/espanso/default.yml"
58
+ end
59
+ puts @leading
60
+ self.config_path=config_path
61
+ self.os_choice = os_choice
62
+ puts "We'll set the config path to:"
63
+ puts @leading
64
+ prompt.ok("#{config_path}")
65
+
66
+ end
67
+
68
+ # REFACTOR TO PROVIDE PATH
69
+ def get_storage()
70
+ puts @leading
71
+ prompt = TTY::Prompt.new
72
+ return snippet_storage = prompt.select("Do your store your snippets in Dropbox or a different directory?", default: 1, active_color: :bright_blue) do |menu|
73
+ menu.enum "."
74
+
75
+ menu.choice "No I use the default folder.", 1
76
+ menu.choice "I use Dropbox.", 2
77
+ menu.choice "I use Google Drive", 3
78
+ menu.choice "I use Another Directory.", 4
79
+ end
80
+ puts @leading
81
+ self.user_storage = snippet_storage
82
+ end
83
+
84
+ def generate_config()
85
+ if File.exist?("#{ENV["HOMEPATH"]}\\snippet_cli_config.txt") && File.read("#{ENV["HOMEPATH"]}\\snippet_cli_config.txt").include?("CONFIG_PRESENT = TRUE")
86
+ else
87
+ File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "NAME = #{self.user_name}\n"}
88
+ File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "#{self.config_path}\n"}
89
+ File.open("#{ENV["HOMEPATH"]}/snippet_cli_config.txt", "a") { |f| f.write "CONFIG_PRESENT = TRUE\n"}
90
+ end
91
+ end
92
+
93
+ def execute(input: $stdin, output: $stdout)
94
+ show_banner()
95
+ self.get_name()
96
+ self.get_os()
97
+ output.puts @leading
98
+ output.puts "Thanks, that's all we need to know about your configuration."
99
+ output.puts @leading
100
+ output.puts @leading
101
+ output.puts "You can now type snippet_cli new to get started."
102
+ output.puts @leading
103
+ self.generate_config()
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1,3 @@
1
+ module SnippetCli
2
+ VERSION = "0.1.4"
3
+ end
@@ -0,0 +1,85 @@
1
+ # Some Definitions for the sake of readability.
2
+ module SnippetGenerator
3
+ NEW_LINE="\n"
4
+ QUOTE = '"'
5
+
6
+ #Just writes matches: at the beginning of file so espanso can read the mapping.
7
+
8
+ def initialize_espanso_yml(file_to_write)
9
+ File.open(file_to_write,"a") { |file| file.write('matches:'+NEW_LINE) }
10
+ end
11
+
12
+ #Writes a snippet to file when given trigger and replacement strings.
13
+
14
+ def single_snippet_export(file_to_write,trigger,replacement)
15
+ File.open(file_to_write,"a") { |file| file.write(NEW_LINE+' - trigger: '+'":'+trigger+QUOTE+NEW_LINE) }
16
+ File.open(file_to_write,"a") { |file| file.write(' replace: |-'+NEW_LINE) }
17
+ if (replacement.instance_of?(String)) then
18
+ File.open(file_to_write,"a") { |file| file.write(' '+replacement) }
19
+ else
20
+ replacement.each do |item|
21
+ File.open(file_to_write,"a") { |file| file.write(' '+item) }
22
+ end
23
+ end
24
+ File.open(file_to_write,"a") { |file| file.write(NEW_LINE) }
25
+ end
26
+
27
+ # New a YAML Comment to separate sections of snippet file.
28
+
29
+ def heading_snippet_export(file_to_write,heading)
30
+ File.open(file_to_write,"a") { |file| file.write("# "+ heading+NEW_LINE) }
31
+ end
32
+
33
+ # Any input fields should be entered with double brackets around them when passed in as form_statement
34
+ # For example "AJ likes coding in {{language}} and using {{editor}} to write code."
35
+
36
+ def input_form_snippet_export(file_to_write, form_trigger,form_statement)
37
+ File.open(file_to_write,"a") { |file| file.write(' - trigger: '+QUOTE+':'+form_trigger+QUOTE+NEW_LINE) }
38
+ File.open(file_to_write,"a") { |file| file.write(' form: |-'+NEW_LINE)}
39
+ if (form_statement.instance_of?(String)) then
40
+ File.open(file_to_write,"a") { |file| file.write(' '+form_statement)}
41
+ else
42
+ form_statement.each do |item|
43
+ File.open(file_to_write,"a") { |file| file.write(' '+item) }
44
+ end
45
+ end
46
+ File.open(file_to_write,"a") { |file| file.write(NEW_LINE) }
47
+ end
48
+ ## ! TO DO: REFACTOR FORM METHODS INTO ONE METHOD which accounts for all cases. Add comments clarifying
49
+ ## ! DATA STRUCTURE NEEDED.
50
+ #Takes a string for trigger. form_values should be an array.form_fields should also be of type array.
51
+ #Parses statements and news picklists based on form fields and values for each field provided
52
+
53
+ def picklist_snippet_export(form_trigger,statement,form_fields,formvalues,file_to_write)
54
+ form_fields.each do |value|
55
+ value+':'
56
+ end
57
+ form_type = 'choice'
58
+ File.open(file_to_write,"a") { |file| file.write(' - trigger: '+'":'+form_trigger+QUOTE+NEW_LINE) }
59
+ File.open(file_to_write,"a") { |file| file.write(' form: '+QUOTE+statement+QUOTE+NEW_LINE) }
60
+ form_fields.each do |value|
61
+ File.open(file_to_write,"a") { |file| file.write(' form_fields:'+NEW_LINE) }
62
+ File.open(file_to_write,"a") { |file| file.write(' '+form_fields+NEW_LINE) }
63
+ File.open(file_to_write,"a") { |file| file.write(' type: '+ form_type+NEW_LINE) }
64
+ File.open(file_to_write,"a") { |file| file.write(' values:'+NEW_LINE) }
65
+ formvalues.each do |value|
66
+ File.open(file_to_write,"a") { |file| file.write(' - '+QUOTE+value+QUOTE+NEW_LINE) }
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ # News a snippet with large text box
73
+
74
+ def textarea_snippet_export(file_to_write)
75
+ File.open(file_to_write,"a") { |file| file.write(' - trigger: '+QUOTE+':'+form_trigger+QUOTE+NEW_LINE) }
76
+ File.open(file_to_write,"a") { |file| file.write(' form: |'+NEW_LINE)}
77
+ File.open(file_to_write,"a") { |file| file.write(' '+form_statement+NEW_LINE)}
78
+ File.open(file_to_write,"a") { |file| file.write(' '+field_names+NEW_LINE) }
79
+ File.open(file_to_write,"a") { |file| file.write(' '+"multiline: true"+NEW_LINE) }
80
+ end
81
+
82
+ ## Form Generator Method. Will make form that has, .
83
+ ## Takes a few arrays as arguments.
84
+ ## Form Fields: Just string in array, but in form context represented as {{Form Field Name}}
85
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/snippet_cli/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "snippet_cli"
5
+ spec.license = "MIT"
6
+ spec.version = SnippetCli::VERSION
7
+ spec.authors = ["AJ Markow"]
8
+ spec.email = ["alexanderjmarkow@gmail.com"]
9
+
10
+ spec.summary = "Allows you to add snippets to Espanso Config from CLI"
11
+ spec.description = "You can write to your espanso config directly using this gem"
12
+ spec.homepage = "https://github.com/ajmarkow/snippet_cli"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/ajmarkow/snippet_cli"
18
+ spec.metadata["changelog_uri"] = "https://github.com/ajmarkow/snippet_cli"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snippet_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - AJ Markow
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: You can write to your espanso config directly using this gem
14
+ email:
15
+ - alexanderjmarkow@gmail.com
16
+ executables:
17
+ - snippet_cli
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".travis.yml"
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - exe/snippet_cli
33
+ - lib/Setup.rb
34
+ - lib/banner.rb
35
+ - lib/info.md
36
+ - lib/snippet_cli.rb
37
+ - lib/snippet_cli/cli.rb
38
+ - lib/snippet_cli/command.rb
39
+ - lib/snippet_cli/commands/.gitkeep
40
+ - lib/snippet_cli/commands/info.rb
41
+ - lib/snippet_cli/commands/new.rb
42
+ - lib/snippet_cli/commands/setup.rb
43
+ - lib/snippet_cli/templates/.gitkeep
44
+ - lib/snippet_cli/templates/config/.gitkeep
45
+ - lib/snippet_cli/templates/create/.gitkeep
46
+ - lib/snippet_cli/templates/info/.gitkeep
47
+ - lib/snippet_cli/templates/setup/.gitkeep
48
+ - lib/snippet_cli/version.rb
49
+ - lib/snippet_generator.rb
50
+ - snippet_cli.gemspec
51
+ homepage: https://github.com/ajmarkow/snippet_cli
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/ajmarkow/snippet_cli
56
+ source_code_uri: https://github.com/ajmarkow/snippet_cli
57
+ changelog_uri: https://github.com/ajmarkow/snippet_cli
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 2.3.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.2.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Allows you to add snippets to Espanso Config from CLI
77
+ test_files: []