marked-conductor 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5d347b6741e69e739cca5e8884cc77c156e2f451297d68a47e34b0593355736
4
+ data.tar.gz: 8c2bf87b1a8ce9f044cde76cb734d416b70d5a7a5ff701430df0c80344ddfe58
5
+ SHA512:
6
+ metadata.gz: b99b245f450a1977b77bceffa87290217465451356e0674c04f66e831c8fac450ec478c8fd25ab84ab532aa9d4a5496e9e8a6269a120d8cf4a00dcc2f6e795c9
7
+ data.tar.gz: d4282745b2540640262c850000e893bc7cbf545674e233982e1ff64a543546c7070b23d0240b82dfdf5ca88ad7a26f20ab1017d6b632c30ad921285657b17ad0
data/.irbrc ADDED
@@ -0,0 +1,3 @@
1
+ require_relative 'lib/conductor'
2
+ include Conductor
3
+
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: single_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: single_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ### 1.0.0
2
+
3
+ 2024-04-25 10:51
4
+
5
+ #### NEW
6
+
7
+ - 1.0 release
8
+
9
+ ### 0.1.0
10
+
11
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at me@brettterpstra.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in marked-conductor.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ marked-conductor (0.1.0)
5
+ chronic (~> 0.10.2)
6
+ tty-which (~> 0.5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ awesome_print (1.9.2)
13
+ chronic (0.10.2)
14
+ coderay (1.1.3)
15
+ json (2.7.2)
16
+ language_server-protocol (3.17.0.3)
17
+ method_source (1.1.0)
18
+ parallel (1.24.0)
19
+ parser (3.3.0.5)
20
+ ast (~> 2.4.1)
21
+ racc
22
+ pry (0.14.2)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
+ racc (1.7.3)
26
+ rainbow (3.1.1)
27
+ rake (13.2.1)
28
+ regexp_parser (2.9.0)
29
+ rexml (3.2.6)
30
+ rubocop (1.63.3)
31
+ json (~> 2.3)
32
+ language_server-protocol (>= 3.17.0)
33
+ parallel (~> 1.10)
34
+ parser (>= 3.3.0.2)
35
+ rainbow (>= 2.2.2, < 4.0)
36
+ regexp_parser (>= 1.8, < 3.0)
37
+ rexml (>= 3.2.5, < 4.0)
38
+ rubocop-ast (>= 1.31.1, < 2.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 2.4.0, < 3.0)
41
+ rubocop-ast (1.31.2)
42
+ parser (>= 3.3.0.4)
43
+ ruby-progressbar (1.13.0)
44
+ tty-which (0.5.0)
45
+ unicode-display_width (2.5.0)
46
+
47
+ PLATFORMS
48
+ arm64-darwin-20
49
+
50
+ DEPENDENCIES
51
+ awesome_print (~> 1.9.2)
52
+ marked-conductor!
53
+ pry (~> 0.14.2)
54
+ rake (~> 13.0)
55
+ rubocop (~> 1.21)
56
+
57
+ BUNDLED WITH
58
+ 2.2.29
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Brett Terpstra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,145 @@
1
+
2
+
3
+ # Marked Conductor
4
+
5
+ A "train conductor" for [Marked 2](https://marked2app.com). Conductor can be set up as a Custom Preprocessor or Custom Processor for Marked, and can run different commands and scripts based on conditions in a YAML configuration file, allowing you to have multiple processors that run based on predicates.
6
+
7
+ ## Installation
8
+
9
+ $ gem install marked-conductor
10
+
11
+ If you run into errors, try running with the `--user-install` flag:
12
+
13
+ $ gem install --user-install marked-conductor
14
+
15
+ > I've noticed lately with `asdf` that I have to run `asdf reshim` after installing gems containing binaries.
16
+
17
+ If you use Homebrew, you can run
18
+
19
+ $ brew gem install marked-conductor
20
+
21
+ ## Usage
22
+
23
+ To use Conductor, you need to set up a configuration file in `~/.config/conductor/tracks.yaml`. Run `conductor` once to create the directory and an empty configuration. See [Configuration](#configuration) below for details on setting up your "tracks."
24
+
25
+ Once configured, you can set up conductor as a Custom Processor in Marked. Run `which conductor | pbcopy` to get the full path to the binary and copy it, then open <b>Marked Preferences > Advanced</b> and select either Custom Processor or Custom Preprocessor (or both) and paste into the <b>Path:</b> field. You can select <i>Automatically enable for new windows</i> to have the processor enabled by default when opening documents.
26
+
27
+
28
+ ![Marked preferences](images/preferences.jpg)
29
+
30
+ Conductor requires that it be run from Marked 2, and won't function on the command line. This is because Marked defines special environment variables that can be used in scripts, and these won't exist when running from your shell. If you want to be able to test Conductor from the command line, see [Testing](#testing).
31
+
32
+ ## Configuration
33
+
34
+ Configuration is done in a YAML file located at `~/.config/conductor/tracks.yaml`. Run `conductor` from the command line to generate the necessary directories and sample config file if it doesn't already exist.
35
+
36
+ The top level key in the YAML file is `tracks:`. This is an array of hashes, each hash containing a `condition` and either a `script` or `command` key.
37
+
38
+ A simple config would look like:
39
+
40
+ ```
41
+ tracks:
42
+ - condition: yaml includes comments
43
+ script: blog-processor
44
+ - condition: any
45
+ command: echo 'NOCUSTOM'
46
+ ```
47
+
48
+ This would run a script at `~/.config/conductor/scripts/blog-processor` if there was YAML present in the document and it included a key called `comments`. If not, the `condition: any` would echo `NOCUSTOM` to Marked, indicating it should skip any Custom Processor. If no condition is met, NOCUSTOM is automatically sent, so this particular example is redundant. In practice you would include a catchall processor to act as the default if no prior conditions were met.
49
+
50
+ Instead of a `script` or `command`, a track can contain another `tracks` key, in which case the parent condition will branch and it will cycle through the tracks contained in the `tracks` key for the hash. `tracks` keys can be repeatedly nested to create AND conditions.
51
+
52
+ For example, the following functions the same as `condition: phase is pre AND tree contains .obsidian AND (extension is md or extension is markdown)`:
53
+
54
+ ```
55
+ tracks:
56
+ - condition: phase is pre
57
+ tracks:
58
+ - condition: tree contains .obsidian
59
+ tracks:
60
+ - condition: extension is md
61
+ command: obsidian-md-filter
62
+ - condition: extension is markdown
63
+ command: obsidian-md-filter
64
+ ```
65
+
66
+ ### Conditions
67
+
68
+ Available conditions are:
69
+
70
+ - `extension` (or `ext`): This will test the extension of the file, e.g. `ext is md` or `ext contains task`
71
+ - `tree contains ...`: This will test whether a given file or directory exists in any of the parent folders of the current file, starting with the current directory of the file. Example: `tree contains .obsidian` would test whether there was an `.obsidian` directory in any of the directories above the file (indicating it's within an Obsidian vault)
72
+ - `path`: This tests just the path itself, allowing conditions like `path contains _drafts` or `path does not contain _posts`.
73
+ - `phase`: Tests whether Marked is in Preprocessor or Processor phase, allowing conditions like `phase is preprocess` or `phase is process` (which can be shortened to `pre` and `pro`).
74
+ - `text`: This tests for any string match within the text of the document being processed. This can be used with operators `starts with`, `ends with`, or `contains`, e.g. `text contains @taskpaper` or `text does not contain <!--more-->`.
75
+ - If the test value is surrounded by forward slashes, it will be treated as a regular expression. Regexes are always flagged as case insensitive. Use it like `text matches @\w+`.
76
+ - `yaml`, `headers`, or `frontmatter` will test for YAML headers. If a `yaml:KEY` is defined, a specific YAML key will be tested for. If a value is defined with an operator, it will be tested against the value key.
77
+ - `yaml` tests for the presence of YAML frontmatter.
78
+ - `yaml:comments` tests for the presence of a `comments` key.
79
+ - `yaml:comments is true` tests whether `comments: true` exists.
80
+ - `yaml:tags contains appreview` will test whether the tags array contains `appreview`.
81
+ - If the YAML key is a date, it can be tested against with `before`, `after`, and `is`, and the value can be a natural language date, e.g. `yaml:date is after may 3, 2024`
82
+ - If both the YAML key value and the test value are numbers, you can use operators `greater than` (`>`), `less than` (`<`), `equal`/`is` (`=`/`==`), and `is not equal`/`not equals` (`!=`/`!==`). Numbers will be interpreted as floats.
83
+ - If the YAML value is a boolean, you can test with `is true` or `is not true` (or `is false`)
84
+ - The following keywords act as a catchall and can be used as the last track in the config to act on any documents that aren't matched by preceding rules:
85
+ - `any`
86
+ - `else`
87
+ - `all`
88
+ - `true`
89
+ - `catchall`
90
+
91
+ Available comparison operators are:
92
+
93
+ - `is` or `equals` (negate with `is not` or `does not equal`) tests for equality on strings, numbers, or dates
94
+ - `contains` or `includes` (negate with `does not contain`) tests on strings or array values
95
+ - `begins with` (or `starts with`) or `ends with` (negate with `does not begin with`) tests on strings
96
+ - `greater than` or `less than` (tests on numbers or dates)
97
+
98
+ Conditions can be combined with AND or OR (must be uppercase) and simple parenthetical operations will work (parenthesis can not be nested). A boolean condition would look like `path contains _posts AND extension is md` or `(tree includes .obsidian AND extension is todo) OR extension is taskpaper`.
99
+
100
+ ### Actions
101
+
102
+ The action can be either `script` or `command`.
103
+
104
+ Scripts are located in `~/.config/conductor/scripts/` and should be executable files that take input on STDIN (unless `$file` is specified in the `script` definition). If a script is defined starting with `~` or `/`, that will be interpreted as a full path to an alternate location.
105
+
106
+ Commands are interpreted as shell commands. If a command exists in the `$PATH`, a full path will automatically be determined, so a command can be as simple as just `pandoc`. Add any arguments needed after the command.
107
+
108
+ Using `$file` as an argument to a script or command will bypass processing of STDIN input, and instead use the value of $MARKED_PATH to read the contents of the specified file.
109
+
110
+ ## Testing
111
+
112
+ In order to test from the command line, you'll need certain environment variables set. This can be done by exporting the following variables with your own definitions, or by running conductor with all of the variables preceding the command, e.g. `$ MARKED_ORIGIN=/path/to/markdown_file.md [...] conductor`.
113
+
114
+ The following need to be defined. Some can be left as empty or to defaults, such as `MARKED_INCLUDES` and `MARKED_OUTLINE`, but all need to be set to something.
115
+
116
+ ```
117
+ HOME=$HOME
118
+ MARKED_CSS_PATH="" # The path to CSS, can be empty
119
+ MARKED_EXT="md" # The extension of the current file in Marked, set as needed for testing
120
+ MARKED_INCLUDES="" # Files included in the document, can be empty
121
+ MARKED_ORIGIN="/Users/ttscoff/notes/" # Base directory for the file being tested
122
+ MARKED_PATH="/Users/ttscoff/notes/markdown_file.md" # Full path to Markdown file
123
+ MARKED_PHASE="PREPROCESS" # either "PROCESS" or "PREPROCESS"
124
+ OUTLINE="none" # Outline mode, can be "none"
125
+ PATH=$PATH # The system $PATH variable
126
+ ```
127
+
128
+ Further, input on STDIN is required, unless the script/command being matched contains `$file`, in which case $MARKED_PATH will be read and operated on. For the purpose of testing, you can use `echo` or `cat FILE` and pipe to conductor, e.g. `echo "TESTING" | conductor`.
129
+
130
+ To test which conditions are being met, you can just set the `command:` for a track to `echo "meaningful message"`, where the message is something that indicates which condition(s) have passed.
131
+
132
+
133
+
134
+ ## Contributing
135
+
136
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/ttscoff/marked-conductor>. 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/ttscoff/marked-conductor/blob/main/CODE_OF_CONDUCT.md).
137
+
138
+ ## License
139
+
140
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
141
+
142
+ ## Code of Conduct
143
+
144
+ Everyone interacting in the Marked::Conductor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ttscoff/marked-conductor/blob/main/CODE_OF_CONDUCT.md).
145
+
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
9
+
10
+ desc "Alias for build"
11
+ task package: :build
12
+
13
+ desc "Development version check"
14
+ task :ver do
15
+ gver = `git ver`
16
+ cver = IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
17
+ res = `grep VERSION lib/conductor/version.rb`
18
+ version = res.match(/VERSION *= *['"](\d+\.\d+\.\d+(\w+)?)/)[1]
19
+ puts "git tag: #{gver}"
20
+ puts "version.rb: #{version}"
21
+ puts "changelog: #{cver}"
22
+ end
23
+
24
+ desc "Changelog version check"
25
+ task :cver do
26
+ puts IO.read(File.join(File.dirname(__FILE__), "CHANGELOG.md")).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
27
+ end
28
+
29
+ desc "Bump incremental version number"
30
+ task :bump, :type do |_, args|
31
+ args.with_defaults(type: "inc")
32
+ version_file = "lib/conductor/version.rb"
33
+ content = IO.read(version_file)
34
+ content.sub!(/VERSION = ["'](?<major>\d+)\.(?<minor>\d+)\.(?<inc>\d+)(?<pre>\S+)?["']/) do
35
+ m = Regexp.last_match
36
+ major = m["major"].to_i
37
+ minor = m["minor"].to_i
38
+ inc = m["inc"].to_i
39
+ pre = m["pre"]
40
+
41
+ case args[:type]
42
+ when /^maj/
43
+ major += 1
44
+ minor = 0
45
+ inc = 0
46
+ when /^min/
47
+ minor += 1
48
+ inc = 0
49
+ else
50
+ inc += 1
51
+ end
52
+
53
+ $stdout.puts "At version #{major}.#{minor}.#{inc}#{pre}"
54
+ "VERSION = '#{major}.#{minor}.#{inc}#{pre}'"
55
+ end
56
+ File.open(version_file, "w+") { |f| f.puts content }
57
+ end
data/bin/conductor ADDED
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/conductor'
5
+
6
+ # raise 'No input on STDIN' unless Conductor.stdin
7
+
8
+ include Conductor
9
+
10
+ config = Config.new
11
+
12
+ def conduct(tracks, res = nil, condition = nil)
13
+ tracks.each do |track|
14
+ cond = Condition.new(track[:condition])
15
+
16
+ next unless cond.true?
17
+
18
+ if track[:tracks]
19
+ ts = track[:tracks].symbolize_keys
20
+
21
+ res, condition = conduct(ts, res, condition)
22
+
23
+ next if res.nil?
24
+ end
25
+
26
+ condition = condition.nil? ? track[:condition] : "#{track[:condition]} > #{condition}"
27
+
28
+ if track[:script]
29
+ script = Script.new(track[:script])
30
+
31
+ res = script.run
32
+ elsif track[:command]
33
+ command = Command.new(track[:command])
34
+
35
+ res = command.run
36
+ end
37
+
38
+ break
39
+ end
40
+
41
+ [res, condition]
42
+ end
43
+
44
+ tracks = config.tracks
45
+ res, condition = conduct(tracks)
46
+
47
+ if res.nil?
48
+ $stderr.puts('No conditions satisfied')
49
+ puts 'NOCUSTOM'
50
+ else
51
+ $stderr.puts("Met condition: #{condition}")
52
+ puts res
53
+ end
54
+
Binary file
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ::Array
4
+
5
+ def symbolize_keys!
6
+ replace symbolize_keys
7
+ end
8
+
9
+ def symbolize_keys
10
+ map { |h| h.symbolize_keys }
11
+ end
12
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Conductor
4
+ # Command runner
5
+ class Command
6
+ attr_reader :args, :path
7
+
8
+ def initialize(command)
9
+ parts = Shellwords.split(command)
10
+ self.path = parts[0]
11
+ self.args = parts[1..].join(' ')
12
+ end
13
+
14
+ def path=(path)
15
+ @path = if path =~ %r{^[%/]}
16
+ File.expand_path(path)
17
+ else
18
+ which = TTY::Which.which(path)
19
+ which || path
20
+ end
21
+ end
22
+
23
+ def args=(array)
24
+ @args = if array.is_a?(Array)
25
+ array.join(' ')
26
+ else
27
+ array
28
+ end
29
+ end
30
+
31
+ def run
32
+ stdin = Conductor.stdin
33
+
34
+ raise 'Command path not found' unless @path
35
+
36
+ use_stdin = true
37
+ if args =~ /\$\{?file\}?/
38
+ use_stdin = false
39
+ args.sub!(/\$\{?file\}?/, %("#{Env.env[:filepath]}"))
40
+ else
41
+ raise 'No input' unless stdin
42
+
43
+ end
44
+
45
+ if use_stdin
46
+ `echo #{Shellwords.escape(stdin)} | #{Env} #{path} #{args}`
47
+ else
48
+ puts "#{Env} #{path} #{args}"
49
+ `#{Env} #{path} #{args}`
50
+ end
51
+ end
52
+ end
53
+ end