markdown_exec 0.2.6 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8baa6b01b9d965c3a8856d08a86225457c09106c366ecd174f7f0e547f43f4a
4
- data.tar.gz: bd0348f31ddb1bb0cda0328e5c7dd3187e6692269e8b132849833ce1d44f5b0f
3
+ metadata.gz: 0f8bb9f8a7a903a6b221ed8d04a5acb445e294be4c134202b9a71ba9e9f7c7ac
4
+ data.tar.gz: d26a89ae33f1aeaac70b40f3e31b3090fb50c6eb48874eeba435ce89825123fc
5
5
  SHA512:
6
- metadata.gz: e6f8028d4fe4dea45bacb14e8cb12306d0ee975ac729c04d0f8db990a6ce92758b13400329358656d5902c85dd5411aef717210b0151de4ae2cec375f51b0b98
7
- data.tar.gz: 390dd965fe49ab4ac1651996fc7500ff971fbe71ce580ff807d8652b62aff5b50768ce971920e9f93682d5adb692cd5bcf99834b8b022c41734dc24f61cf940c
6
+ metadata.gz: f177057c231ef950012abc922b6c3d9611e0b423df57cee07e6ac0e68864c18ce9b6a7cf640e165dbd8409d6ecefb199a3bb31643a7c5e31d5c241f17682545e
7
+ data.tar.gz: 9fb1a5d4274d2443e1ed9680978cfb12c76b46416a3ba76483addd19b61238446dce86793a039cfede131bdd11a4436ae693640ad279add82e24415a544b7b53
data/CHANGELOG.md CHANGED
@@ -2,31 +2,97 @@
2
2
 
3
3
  ## [ToDo]
4
4
 
5
- - pipe stdin to script
6
- - yes/no/write/clipboard/record/edit/history
7
- - present timestamp, result of last exec for each command
8
5
  - user settings
9
6
  - hidden w , w/o () in names
10
7
  - fix regexp in pathnames
11
- - tab completion from md file
12
- - read file once to allow for tempdoc stream
13
- - include md or blocks file
8
+
9
+ - [ ] read file once to allow for tempdoc stream
14
10
 
15
11
  - tree display
16
12
 
17
- - mde options in md file or included file
13
+ - [ ] mde options, user prompt, in md file or included file
14
+
15
+ - [ ] include blocks from local md file
16
+
17
+ - execute? yes/no/save/clipboard + record/edit/history
18
+
19
+ - [ ] list, view saved output
20
+
21
+ - completion
22
+ - [ ] include blocks in md file
23
+
24
+ - [ ] ruby gem data model
25
+
26
+ - [ ] extract yaml block into stdout
27
+ - [ ] extract json block into stdout
28
+
29
+ - [ ] import yaml, json data into environment
18
30
 
19
- - include blocks from local md file
31
+ - [ ] yq filter with imported or named yaml, json data
20
32
 
21
- - chmod a+x logged script
33
+ - [ ] yaml dump of options w/ detail
34
+
35
+ - [ ] re-exec last script v re-run named block in last script
36
+ - [ ] repeat to reload last doc and block
37
+ - [ ] option to log blended, timeline; stdin, stdout, stderr; labels: prefix and blocks
38
+ - [ ] ren logged_stdout_filename_prefix to saved_stdout_filename_prefix
39
+
40
+ ## [1.1.1] - 2022-05-25
41
+
42
+ ### Added
43
+
44
+ - Post-install instructions to add tab completions permanently to the shell.
45
+
46
+ ### Changed
47
+
48
+ - Improve handling of threads ending while executing scripts.
49
+
50
+ ## [1.1.0] - 2022-05-21
51
+
52
+ ### Added
53
+
54
+ - Display administrative output (command, save files) for executed blocks.
55
+ - Select base, administrative output as hierarchical output (MDE_DISPLAY_LEVEL).
56
+ - The user may select Exit, the first option, to quit the program.
57
+ - The block-selection menu is re-displayed after an approved script is exectued.
58
+ - Pause for and pass through standard input in scripts executed by the tool.
59
+ - Options
60
+ - chmod for saved scripts
61
+ - shebang for saved scripts
62
+ - shell for executed and saved scripts
63
+
64
+ ### Changed
65
+
66
+ - Exit option is at top of each menu.
67
+ - Single-stage tab completion, default
68
+ - Presents matching options when current word starts with `-`
69
+ - Presents directories and files otherwise.
70
+ - Two-stage tab completion for option arguments.
71
+ - When prior word is an option and current word is empty
72
+ - Presents option type on first tab, eg `.BOOL.` for a boolean option.
73
+ - Presents option default value on second tab, eg `0` for false.
74
+ - Write STDOUT, STDERR, STDIN in sections to saved output file.
75
+
76
+ ## [1.0.0] - 2022-04-26
77
+
78
+ ### Added
79
+
80
+ - Command `--pwd` to print the gem's home folder.
81
+ - Command `--select-recent-output` to select and open a recent output log file.
82
+ e.g. `MDE_OUTPUT_VIEWER_OPTIONS="-a '/Applications/Sublime Text.app'" mde --select-recent-output`
83
+ - Command `--tab-completions` to list the application options.
84
+ - Tab completion script for Bash shell.
85
+
86
+ ### Changed
22
87
 
23
- - add shebang to saved script
88
+ - File names for saved scripts.
89
+ - Hide blocks with empty names, e.g. `:()`.
24
90
 
25
91
  ## [0.2.6] - 2022-04-07
26
92
 
27
93
  ### Changed
28
94
 
29
- - Fixed default values for command line options.
95
+ - Default values for command line options.
30
96
 
31
97
  ## [0.2.5] - 2022-04-03
32
98
 
data/Gemfile CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in markdown_exec.gemspec
6
5
  gemspec
7
-
8
- gem 'rake', '~> 13.0'
9
-
6
+ gem 'clipboard'
7
+ gem 'erb'
10
8
  gem 'minitest', '~> 5.0'
11
-
9
+ gem 'mrdialog', '~> 1.0.3'
10
+ gem 'rake', '~> 13.0'
12
11
  gem 'rubocop', '~> 1.21'
13
12
  gem 'rubocop-minitest', require: false
14
13
  gem 'rubocop-rake', require: false
14
+ gem 'shellwords'
15
+ gem 'uri'
16
+ gem 'yaml'
data/Gemfile.lock CHANGED
@@ -1,7 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (0.2.5)
4
+ markdown_exec (1.1.1)
5
+ clipboard (~> 1.3.6)
6
+ mrdialog (~> 1.0.3)
5
7
  open3 (~> 0.1.1)
6
8
  optparse (~> 0.1.1)
7
9
  tty-prompt (~> 0.23.1)
@@ -11,7 +13,12 @@ GEM
11
13
  remote: https://rubygems.org/
12
14
  specs:
13
15
  ast (2.4.2)
16
+ cgi (0.3.2)
17
+ clipboard (1.3.6)
18
+ erb (2.2.3)
19
+ cgi
14
20
  minitest (5.15.0)
21
+ mrdialog (1.0.3)
15
22
  open3 (0.1.1)
16
23
  optparse (0.1.1)
17
24
  parallel (1.21.0)
@@ -39,6 +46,7 @@ GEM
39
46
  rubocop-rake (0.6.0)
40
47
  rubocop (~> 1.0)
41
48
  ruby-progressbar (1.11.0)
49
+ shellwords (0.1.0)
42
50
  tty-color (0.6.0)
43
51
  tty-cursor (0.7.1)
44
52
  tty-prompt (0.23.1)
@@ -50,6 +58,7 @@ GEM
50
58
  wisper (~> 2.0)
51
59
  tty-screen (0.8.1)
52
60
  unicode-display_width (2.1.0)
61
+ uri (0.11.0)
53
62
  wisper (2.0.1)
54
63
  yaml (0.2.0)
55
64
 
@@ -57,12 +66,18 @@ PLATFORMS
57
66
  arm64-darwin-21
58
67
 
59
68
  DEPENDENCIES
69
+ clipboard
70
+ erb
60
71
  markdown_exec!
61
72
  minitest (~> 5.0)
73
+ mrdialog (~> 1.0.3)
62
74
  rake (~> 13.0)
63
75
  rubocop (~> 1.21)
64
76
  rubocop-minitest
65
77
  rubocop-rake
78
+ shellwords
79
+ uri
80
+ yaml
66
81
 
67
82
  BUNDLED WITH
68
83
  2.2.32
data/README.md CHANGED
@@ -55,6 +55,10 @@ Process `README.md` file in the current folder. Displays all the blocks in the f
55
55
 
56
56
  Select a block to execute from `my.md`.
57
57
 
58
+ #### `mde my.md myblock`
59
+
60
+ Execute the block named `myblock` from `my.md`.
61
+
58
62
  #### `mde .` or `mde -p .`
59
63
 
60
64
  Select a markdown file in the current folder. Select a block to execute from that file.
@@ -142,7 +146,40 @@ Boolean options configured with environment variables:
142
146
  - Specify variable on command line.
143
147
  e.g. `MDE_SAVE_EXECUTED_SCRIPT=1 mde`
144
148
 
145
- # Example blocks
149
+ ## Tab Completion
150
+
151
+ ### Install tab completion
152
+
153
+ Append a command to load the completion script to your shell configuration file. `mde` must be executable for the command to be composed correctly.
154
+
155
+ ```bash :()
156
+ echo "source $(mde --pwd)/bin/tab_completion.sh" >> ~/.bash_profile
157
+ ```
158
+
159
+ ### Behavior
160
+
161
+ Press tab for completions appropriate to the current input.
162
+ `mde <...> <prior word> <current word>`
163
+
164
+ Completions are calculated based on the current word and the prior word.
165
+ 1. If the current word starts with `-`, present matching options, eg `--version` for the current word `--v`.
166
+ 2. Else, if the current word is empty and the prior word is an option that takes an argument, present the type of the argument, eg `.BOOL.` for the option `--user-must-approve`.
167
+ 3. Else, if the current word is the type of argument, from the rule above, present the default value for the option. e.g. `1` for the type `.BOOL.` for the option `--user-must-approve`.
168
+ 4. Else, if the current word is non-empty, list matching files and folders.
169
+
170
+ ### Example Completions
171
+
172
+ In the table below, tab is indicated by `!`
173
+ | Input | Completions |
174
+ | :---: | :---: |
175
+ | `mde !` | local files and folders |
176
+ | `mde -!` | all options |
177
+ | `mde --!` | all options |
178
+ | `mde --v!` | `mde --version` |
179
+ | `mde --user-must-approve !` | `mde --user-must-approve .BOOL.`|
180
+ | `mde --user-must-approve .BOOL.!` | `mde --user-must-approve 1` |
181
+
182
+ ## Example Blocks
146
183
 
147
184
  When prompted, select either the `awake` or `asleep` block.
148
185
 
@@ -166,17 +203,6 @@ export ACTIVITY=asleep
166
203
  echo "$TIME -> $ACTIVITY"
167
204
  ```
168
205
 
169
- ``` :missing_command
170
- fail
171
- ```
172
-
173
- ``` :exit_value
174
- echo "a"
175
- echo "b"
176
- echo "c" >>/dev/stderr
177
- grep nx Gemfile
178
- ```
179
-
180
206
  # License
181
207
 
182
208
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  require 'bundler/gem_tasks'
4
4
  require 'rake/testtask'
5
+ require 'erb'
6
+ require 'yaml'
7
+
8
+ require_relative 'lib/shared'
5
9
 
6
10
  Rake::TestTask.new(:test) do |task|
7
11
  task.libs << 'test'
@@ -12,7 +16,7 @@ end
12
16
  require 'rubocop/rake_task'
13
17
 
14
18
  RuboCop::RakeTask.new do |task|
15
- # task.requires << 'rubocop-minitest'
19
+ task.requires << 'rubocop-minitest'
16
20
  end
17
21
 
18
22
  desc 'named task because minitest not included in rubocop tests'
@@ -50,3 +54,33 @@ desc 'gem build clean'
50
54
  task :clean do
51
55
  system 'rm *.gem'
52
56
  end
57
+
58
+ private
59
+
60
+ BF = 'bin'
61
+
62
+ def update_tab_completion(target)
63
+ words = `#{File.join BF, MarkdownExec::BIN_NAME} --tab-completions`.split("\n")
64
+ mde_tab_completions = '(' + (words.map { |s| "\"#{s}\"" }).join(' ') + ')'
65
+ mde_help = `#{File.join BF, MarkdownExec::BIN_NAME} --help`.split("\n")
66
+ menu_export_yaml = `#{File.join BF, MarkdownExec::BIN_NAME} --menu-export`
67
+
68
+ svhs = YAML.load menu_export_yaml # rubocop:disable Security/YAMLLoad
69
+ svhs.each do |svh|
70
+ svh[:compreply] = value_for_cli(svh[:default]) if svh[:compreply].nil?
71
+ end.tap_inspect name: :svhs, format: :yaml
72
+
73
+ File.write target, ERB.new(File.read(File.join(BF, 'tab_completion.sh.erb'))).result(binding)
74
+ end
75
+
76
+ desc 'update tab_completion.sh'
77
+ task :update_tab_completion do
78
+ update_tab_completion File.join(BF, 'tab_completion.sh')
79
+ end
80
+
81
+ desc 'update tab_completion.sh'
82
+ task :update_installed_tab_completion do
83
+ update_tab_completion(fs = File.join(`mde --pwd`.chomp, BF, 'tab_completion.sh'))
84
+
85
+ puts `cat #{fs}` ###
86
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env bash
2
+
3
+ __filedirs()
4
+ {
5
+ local IFS=$'\n'
6
+ COMPREPLY=( $(compgen -o plusdirs -f -- "${cur}") )
7
+ # COMPREPLY=( $(compgen -d) $(compgen -f -- "${cur}") )
8
+ }
9
+
10
+ __filedirs_all()
11
+ {
12
+ COMPREPLY='.'
13
+ }
14
+
15
+ _mde_echo_version() {
16
+ echo "1.1.1"
17
+ }
18
+
19
+ _mde() {
20
+ local cur prev opts
21
+ cur="${COMP_WORDS[COMP_CWORD]}"
22
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
23
+ # printf '%s' "-;${prev}-:${cur}-"
24
+
25
+ # current word is an option type
26
+ # if previous word is an option name
27
+ # stage 2: replace with option default value
28
+ #
29
+ if [[ "${cur}" =~ ^\..+\.$ ]] ; then
30
+ if [[ ${prev} == -* ]] ; then
31
+ case $prev in
32
+
33
+ --config) COMPREPLY="."; return 0 ;;
34
+
35
+ --debug) COMPREPLY="0"; return 0 ;;
36
+
37
+ --display-level) COMPREPLY="1"; return 0 ;;
38
+
39
+ --filename) COMPREPLY="."; return 0 ;;
40
+
41
+ --list-count) COMPREPLY="32"; return 0 ;;
42
+
43
+ --logged-stdout-filename-prefix) COMPREPLY="mde"; return 0 ;;
44
+
45
+ --output-execution-summary) COMPREPLY="0"; return 0 ;;
46
+
47
+ --output-script) COMPREPLY="0"; return 0 ;;
48
+
49
+ --output-stdout) COMPREPLY="1"; return 0 ;;
50
+
51
+ --path) COMPREPLY="."; return 0 ;;
52
+
53
+ --save-executed-script) COMPREPLY="0"; return 0 ;;
54
+
55
+ --save-execution-output) COMPREPLY="0"; return 0 ;;
56
+
57
+ --saved-script-chmod) COMPREPLY="493"; return 0 ;;
58
+
59
+ --saved-script-filename-prefix) COMPREPLY="mde"; return 0 ;;
60
+
61
+ --saved-script-folder) COMPREPLY="logs"; return 0 ;;
62
+
63
+ --saved-script-glob) COMPREPLY="mde_\*.sh"; return 0 ;;
64
+
65
+ --saved-stdout-folder) COMPREPLY="logs"; return 0 ;;
66
+
67
+ --saved-stdout-glob) COMPREPLY="mde_\*.out.txt"; return 0 ;;
68
+
69
+ --user-must-approve) COMPREPLY="1"; return 0 ;;
70
+
71
+ esac
72
+ fi
73
+ fi
74
+
75
+ # current word is an option name or start of
76
+ # present matching option names
77
+ #
78
+ if [[ ${cur} == -* ]] ; then
79
+ opts=("--list-blocks" "--list-default-env" "--list-default-yaml" "--list-docs" "--list-recent-output" "--list-recent-scripts" "--pwd" "--run-last-script" "--select-recent-output" "--select-recent-script" "--menu-export" "--tab-completions" "--help" "--version" "--exit" "--config" "--debug" "--display-level" "--block-name" "--filename" "--list-count" "--logged-stdout-filename-prefix" "--output-execution-summary" "--output-script" "--output-stdout" "--path" "--save-executed-script" "--save-execution-output" "--saved-script-chmod" "--saved-script-filename-prefix" "--saved-script-folder" "--saved-script-glob" "--saved-stdout-folder" "--saved-stdout-glob" "--user-must-approve")
80
+ COMPREPLY=( $(compgen -W "$(printf "'%s' " "${opts[@]}")" -- "${cur}") )
81
+
82
+ return 0
83
+ fi
84
+
85
+ # no current word
86
+ # if previous word is an option name
87
+ # stage 1: present option type
88
+ #
89
+ if [[ -z ${cur} ]] ; then
90
+ case $prev in
91
+
92
+ --config) COMPREPLY=".PATH."; return 0 ;;
93
+
94
+ --debug) COMPREPLY=".BOOL."; return 0 ;;
95
+
96
+ --display-level) COMPREPLY=".INT.0-2."; return 0 ;;
97
+
98
+ --block-name) COMPREPLY=".NAME."; return 0 ;;
99
+
100
+ --filename) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
101
+
102
+ --list-count) COMPREPLY=".INT.1-."; return 0 ;;
103
+
104
+ --logged-stdout-filename-prefix) COMPREPLY=".PREFIX."; return 0 ;;
105
+
106
+ --output-execution-summary) COMPREPLY=".BOOL."; return 0 ;;
107
+
108
+ --output-script) COMPREPLY=".BOOL."; return 0 ;;
109
+
110
+ --output-stdout) COMPREPLY=".BOOL."; return 0 ;;
111
+
112
+ --path) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
113
+
114
+ --save-executed-script) COMPREPLY=".BOOL."; return 0 ;;
115
+
116
+ --save-execution-output) COMPREPLY=".BOOL."; return 0 ;;
117
+
118
+ --saved-script-chmod) COMPREPLY=".INT."; return 0 ;;
119
+
120
+ --saved-script-filename-prefix) COMPREPLY=".PREFIX."; return 0 ;;
121
+
122
+ --saved-script-folder) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
123
+
124
+ --saved-script-glob) COMPREPLY=".GLOB."; return 0 ;;
125
+
126
+ --saved-stdout-folder) COMPREPLY=".RELATIVE_PATH."; return 0 ;;
127
+
128
+ --saved-stdout-glob) COMPREPLY=".GLOB."; return 0 ;;
129
+
130
+ --user-must-approve) COMPREPLY=".BOOL."; return 0 ;;
131
+
132
+ esac
133
+ fi
134
+
135
+ # current word is unrecognized
136
+ # present matching directory or file names
137
+ #
138
+ __filedirs
139
+ }
140
+
141
+ complete -o filenames -o nospace -F _mde mde
142
+ # _mde_echo_version
143
+ # echo "Updated: 2022-05-26 01:40:10 UTC"
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env bash
2
+
3
+ __filedirs()
4
+ {
5
+ local IFS=$'\n'
6
+ COMPREPLY=( $(compgen -o plusdirs -f -- "${cur}") )
7
+ # COMPREPLY=( $(compgen -d) $(compgen -f -- "${cur}") )
8
+ }
9
+
10
+ __filedirs_all()
11
+ {
12
+ COMPREPLY='.'
13
+ }
14
+
15
+ _mde_echo_version() {
16
+ echo "<%= MarkdownExec::VERSION %>"
17
+ }
18
+
19
+ _mde() {
20
+ local cur prev opts
21
+ cur="${COMP_WORDS[COMP_CWORD]}"
22
+ prev="${COMP_WORDS[COMP_CWORD-1]}"
23
+ # printf '%s' "-;${prev}-:${cur}-"
24
+
25
+ # current word is an option type
26
+ # if previous word is an option name
27
+ # stage 2: replace with option default value
28
+ #
29
+ if [[ "${cur}" =~ ^\..+\.$ ]] ; then
30
+ if [[ ${prev} == -* ]] ; then
31
+ case $prev in
32
+ <% svhs.each do |svh|
33
+ svn = svh[:long_name]
34
+ if svn && svh[:arg_name]
35
+ svn = '--' + svh[:long_name]
36
+ if svh[:compreply] == false
37
+ # nothing
38
+ elsif svh[:compreply].nil? %>
39
+ <%= svn + ') __filedirs_all; return 0 ;;' %>
40
+ <% elsif svh[:compreply].empty?
41
+ # nothing
42
+ else %>
43
+ <%= svn + ') COMPREPLY="' + svh[:compreply] + '"; return 0 ;;' %>
44
+ <% end
45
+ end
46
+ end %>
47
+ esac
48
+ fi
49
+ fi
50
+
51
+ # current word is an option name or start of
52
+ # present matching option names
53
+ #
54
+ if [[ ${cur} == -* ]] ; then
55
+ opts=<%= mde_tab_completions %>
56
+ COMPREPLY=( $(compgen -W "$(printf "'%s' " "${opts[@]}")" -- "${cur}") )
57
+
58
+ return 0
59
+ fi
60
+
61
+ # no current word
62
+ # if previous word is an option name
63
+ # stage 1: present option type
64
+ #
65
+ if [[ -z ${cur} ]] ; then
66
+ case $prev in
67
+ <% svhs.each do |svh|
68
+ svn = svh[:long_name]
69
+ if svn && svh[:arg_name]
70
+ svn = '--' + svh[:long_name] %>
71
+ <%= svn + ') COMPREPLY=".' + svh[:arg_name] + '."; return 0 ;;' %>
72
+ <% end
73
+ end %>
74
+ esac
75
+ fi
76
+
77
+ # current word is unrecognized
78
+ # present matching directory or file names
79
+ #
80
+ __filedirs
81
+ }
82
+
83
+ complete -o filenames -o nospace -F _mde mde
84
+ # _mde_echo_version
85
+ # echo "Updated: <%= Time.now.utc %>"
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MarkdownExec
4
- APP_NAME = 'MDE'
5
4
  APP_DESC = 'Markdown Executor'
5
+ APP_NAME = 'MDE'
6
+ BIN_NAME = 'mde'
6
7
  GEM_NAME = 'markdown_exec'
7
- VERSION = '0.2.6'
8
+ VERSION = '1.1.1'
8
9
  end