rmux 0.3.1 → 0.5.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab87e46abc418f3c0279f95634d75563b5e69522d8e60bb823bdbf26823480f4
4
- data.tar.gz: fc9a440bc0a5c72c48ab451c75e0d87a3a3b56a9b508024f66409d9bb0707e49
3
+ metadata.gz: b5f42cc5291cecf577a50da996b8afb16a0d06ee4fb651d80da4cf5476e75009
4
+ data.tar.gz: 1a3ac9b86ae3de6a0bc07748d2d42b0ff05f2540db05feb2c5d0fb652b1cd850
5
5
  SHA512:
6
- metadata.gz: b4285774e467a7dae25100ba614e021c42c28a17ab991f15ddc82bd57fa8e3b0a267976dbc32967daee0674190186da85b98491fa5df62fbf9c0176f31b9142f
7
- data.tar.gz: 5e4c2433f317bfb3bb7765f53bd0a6daf31893d2bed881d9d5ee1fda5d1fba3ff3c2ab7fde393f516cc90581803118e3bee8c3b9698edb9970c4b8323009fc9b
6
+ metadata.gz: ca1337fc3d0177a7da1e98b458f075fd954e3b2c00c8abef9391a974a8ced9210dcd811da7faf07e65d5b0cf034625b90cb85050711ddf000761220514ddb6af
7
+ data.tar.gz: '084b0dc3182376f3adbe0b4c0bf8519add8aabda36d62546c3229638a8e976f2bb1eef8ccccff2badcc74967cb4b98e2562fa48534a2097cc95883ee49f8e0a1'
data/README.md CHANGED
@@ -21,6 +21,23 @@ the code of the two repos concerned.
21
21
  PRs/issues for better integrations might be considered if
22
22
  you flatten me enough (or rather the contrary)
23
23
 
24
+ ## Environnement
25
+
26
+ ### `Lab42TmuxThemes`
27
+
28
+ optional but needed to use the `tmux_theme` command.
29
+ It shall point to a direcory of files with an `zsh` extension (but
30
+ containing tmux commands, as they will be sourced by tmux)
31
+
32
+ ### `Lab42CompiledProjectDir`
33
+
34
+ optional but if not set must be provided with the -s|--session_dir
35
+ argument.
36
+ It shall point to a directory containing session description files
37
+ with an `rb` extension.
38
+
39
+ optional but needed to run the `rmux` binary, it it is set the call
40
+
24
41
 
25
42
  # Author
26
43
 
data/bin/rmux CHANGED
@@ -1,5 +1,21 @@
1
+ #!/usr/bin/env ruby
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require_relative '../lib/rmux'
4
- Rmux.new.run(ARGV) if $PROGRAM_NAME == __FILE__
5
+
6
+ raise "Must not be required" unless $PROGRAM_NAME == __FILE__
7
+ case ARGV.first
8
+ when '-s', '--session-dir'
9
+ session_dir = ARGV[1]
10
+ args = [session_dir, *ARGV.drop(2)]
11
+ else
12
+ message =
13
+ "neither the -s|--session-dir switch, nor the environment variable RmuxSessionDescriptionsDir were provided"
14
+ session_dir = ENV.fetch('RmuxSessionDescriptionsDir') do
15
+ raise ArgumentError, message
16
+ end
17
+ args = [session_dir, *ARGV]
18
+ end
19
+
20
+ Rmux.new.run(args)
5
21
  # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -8,11 +8,11 @@ class Rmux
8
8
 
9
9
  attr_reader :session_data, :value
10
10
 
11
- def check_data(session_data)
11
+ def check_data(session_data, options=OpenStruct.new)
12
12
  @session_data = session_data
13
13
  @value = {}
14
14
 
15
- check_session_name
15
+ check_session_name unless options.in_tmux
16
16
  check_home_dir
17
17
  check_target_window
18
18
  check_tmux_theme
data/lib/rmux/compiler.rb CHANGED
@@ -6,12 +6,16 @@ class Rmux
6
6
 
7
7
  class Compiler
8
8
 
9
- attr_reader :home_dir, :session_data, :session_name, :target_window, :tmux_theme, :window_preludes
9
+ attr_reader :home_dir,
10
+ :options,
11
+ :session_data, :session_name,
12
+ :target_window, :tmux_theme,
13
+ :window_preludes
10
14
 
11
- # TODO: read from config v0.2.0
15
+ # TODO: read from config v0.?.?
12
16
  NEW_WINDOW_PREFIX = 'FORCE_LOAD=1 source /Users/robert/etc/lab42-myzsh/lab42-my.zsh'
13
17
  def compile
14
- checked = Checker.new.check_data(session_data)
18
+ checked = Checker.new.check_data(session_data, options)
15
19
  # $stderr.puts(checked.inspect)
16
20
  case checked
17
21
  in {ok: true, value:}
@@ -24,7 +28,8 @@ class Rmux
24
28
 
25
29
  private
26
30
 
27
- def initialize(session_data)
31
+ def initialize(session_data, options=OpenStruct.new)
32
+ @options = options
28
33
  @session_data = session_data
29
34
  end
30
35
 
@@ -36,10 +41,10 @@ class Rmux
36
41
 
37
42
  def _compile(data)
38
43
  set_ivars_from(data)
39
- compile_session_head
40
- compile_window_prelude(0)
44
+ compile_session_head unless options.in_tmux
45
+ compile_window_prelude(0) unless options.in_tmux
41
46
  compile_windows
42
- compile_final_attach
47
+ compile_final_attach unless options.in_tmux
43
48
  end
44
49
 
45
50
  def compile_final_attach
@@ -5,7 +5,7 @@ class Rmux
5
5
  module BuiltIn
6
6
  def irb_window(name = "ruby-console", *cmds, &blk)
7
7
  # if blk
8
- windows << Window.new(name, *[*cmds, "RUBYLIB=./lib bundle exec irb"], &blk)
8
+ windows << Window.new(name, nil, *[*cmds, "RUBYLIB=./lib bundle exec irb"], &blk)
9
9
  # else
10
10
  # windows << Window.new(name, *[*cmds, "bundle exec irb -I./lib"], &blk)
11
11
  # end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Rmux
4
+ class Data
5
+ module Common
6
+ module WindowCommands
7
+ def browser_sync(filter: "*.html", index: "index.html")
8
+ command "browser-sync start --server --files #{filter} --index #{index}"
9
+ end
10
+
11
+ def cd(*path)
12
+ command("cd #{path.flatten.join("/")}")
13
+ end
14
+
15
+ def command(*cmds)
16
+ cmds.flatten.each { commands << it }
17
+ end
18
+
19
+ def commands
20
+ @__commands__ ||= []
21
+ end
22
+
23
+ def home_dir(path) = (home_dirs << path)
24
+
25
+ def home_dirs
26
+ @__home_dirs__ ||= []
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
33
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../common/window_commands'
4
+ class Rmux
5
+ class Data
6
+ class Window
7
+ class Pane
8
+ include Common::WindowCommands
9
+
10
+ attr_reader :format, :size
11
+
12
+ def to_hash
13
+ {pane_commands: commands, size:, format:}
14
+ end
15
+
16
+ private
17
+ def initialize(pane_commands:, size:, format:, &blk)
18
+ @__commands__ = pane_commands unless pane_commands.empty?
19
+ @size = size
20
+ @format = format
21
+ instance_exec(&blk) if blk
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
28
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -1,38 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'window/pane'
3
4
  class Rmux
4
5
  class Data
5
6
  class Window
7
+ include Common::WindowCommands
6
8
 
7
- attr_reader :name
8
-
9
- def browser_sync(filter: "*.html", index: "index.html")
10
- command "browser-sync start --server --files #{filter} --index #{index}"
11
- end
12
- def command(*cmds)
13
- cmds.flatten.each { commands << it }
14
- end
15
-
16
- def commands
17
- @__commands__ ||= []
18
- end
9
+ attr_reader :home_dir, :name
19
10
 
20
11
  def panes
21
12
  @__panes__ ||= []
22
13
  end
23
14
 
24
- def hsplit(*commands, size: "50%") = __split(commands, size:, format: 'h')
25
- def vsplit(*commands, size: "50%") = __split(commands, size:, format: 'v')
15
+ def hsplit(*commands, dir: nil, size: "50%", &blk) = __split(commands, dir:, size:, format: 'h', &blk)
16
+ def vsplit(*commands, dir: nil, size: "50%", &blk) = __split(commands, dir:, size:, format: 'v', &blk)
26
17
 
27
18
  private
28
- def initialize(name, *cmds, &blk)
19
+ def initialize(name, home_dir, *cmds, &blk)
29
20
  @name = name
21
+ @home_dir = home_dir
30
22
  cmds.flatten.each { commands << it }
31
23
  instance_exec(&blk) if blk
32
24
  end
33
25
 
34
- def __split(pane_commands, size:, format:)
35
- panes << {pane_commands:, size:, format:}
26
+ def __split(pane_commands, dir:, size:, format:, &blk)
27
+ pane_commands = ["cd #{File.join(home_dir, dir)}", *pane_commands] if dir
28
+ panes << Pane.new(pane_commands:, size:, format:, &blk)
36
29
  end
37
30
  end
38
31
  end
data/lib/rmux/data.rb CHANGED
@@ -9,6 +9,7 @@ class Rmux
9
9
  class Data
10
10
  include BuiltIn
11
11
  include Helper
12
+ include Common::WindowCommands
12
13
 
13
14
  def import(file, **args)
14
15
  path = Tools::File.join_with_ext(@base_dir, file, 'rb')
@@ -17,16 +18,10 @@ class Rmux
17
18
  instance_eval content
18
19
  end
19
20
 
20
- def home_dir(path) = (home_dirs << path)
21
-
22
21
  def arguments
23
22
  @__arguments__ ||= {}
24
23
  end
25
24
 
26
- def home_dirs
27
- @__home_dirs__ ||= []
28
- end
29
-
30
25
  def session_name(name) = (session_names << name)
31
26
 
32
27
  def session_prelude(cmd) = (session_preludes << cmd)
@@ -59,7 +54,7 @@ class Rmux
59
54
  end
60
55
 
61
56
  def window(name, *cmds, &blk)
62
- windows << Window.new(name, *cmds, &blk)
57
+ windows << Window.new(name, home_dirs.first, *cmds, &blk)
63
58
  end
64
59
 
65
60
  def windows
data/lib/rmux/runner.rb CHANGED
@@ -15,7 +15,7 @@ class Rmux
15
15
  return display_session_data if option.interpret_only
16
16
 
17
17
  # $stderr.puts "SESSION_NAME: #{session_data.session_names}"
18
- case Compiler.new(session_data).compile
18
+ case Compiler.new(session_data, option).compile
19
19
  in {ok: true, value: commands}
20
20
  # $stderr.puts "FIRST: #{commands.first}"
21
21
  Commander.issue_commands(commands, debug: option.debug)
@@ -25,8 +25,9 @@ class Rmux
25
25
  end
26
26
 
27
27
  private
28
- def initialize(base_dir, file, option=nil)
28
+ def initialize(base_dir, file, option=nil, in_tmux: false)
29
29
  set_option(option)
30
+ @option.in_tmux = in_tmux
30
31
  @data = Data.new(base_dir)
31
32
  @file = file
32
33
  end
data/lib/rmux/tmux.rb CHANGED
@@ -24,12 +24,15 @@ class Rmux
24
24
  def new_window_init(cmds, session_name:, win_id:, pane_id: nil)
25
25
  target = _target(session_name:, win_id:, pane_id:)
26
26
  cmds = cmds.zip([";"] * cmds.length.pred)
27
+ cmds = [["alias last_rmux_command='#{cmds.last.first}'", ";"], *cmds]
27
28
  send_cmds = cmds.flat_map do |cmd, sep|
28
29
  [
29
30
  "tmux send-keys #{target} #{Shellwords.shellescape cmd}",
30
31
  ("tmux send-keys #{target} '; '" if sep)
31
32
  ].compact
32
33
  end
34
+ # require "debug"; binding.break
35
+ # send_cmds << "tmux send-keys #{target}
33
36
  send_cmds << "tmux send-keys #{target} C-m"
34
37
  end
35
38
 
data/lib/rmux.rb CHANGED
@@ -20,7 +20,7 @@ class Rmux
20
20
  attr_reader :data, :session_data
21
21
 
22
22
  class << self
23
- def version = "0.3.1"
23
+ def version = "0.5.3"
24
24
  end
25
25
 
26
26
  def run(args)
@@ -31,8 +31,12 @@ class Rmux
31
31
  return Tools::Color.putsc(version)
32
32
  when '-h', '--help'
33
33
  return Tools::Color.putsc(HELPTEXT)
34
+ end
35
+
36
+ if ENV['TMUX']
37
+ run_in_tmux(args)
34
38
  else
35
- run_file(args)
39
+ run_new(args)
36
40
  end
37
41
  end
38
42
 
@@ -40,7 +44,12 @@ class Rmux
40
44
 
41
45
  private
42
46
 
43
- def run_file(args) = Runner.new(*args).run
44
- end
47
+ def run_in_tmux(args)
48
+ Runner.new(*args, in_tmux: true).run
49
+ end
45
50
 
51
+ def run_new(args)
52
+ Runner.new(*args).run
53
+ end
54
+ end
46
55
  # SPDX-License-Identifier: AGPL-3.0-or-later
data/lib/tools/color.rb CHANGED
@@ -1,16 +1,15 @@
1
1
  # tfrozen_string_literal: true
2
2
 
3
- require 'ex_aequo/colorize'
4
-
5
3
  module Tools
6
4
  module Color extend self
7
5
  def col(lines)
8
- case ExAequo::Colorizer.colorize(lines)
9
- in {ok: true, result:}
10
- result
11
- in {ok: false, message:}
12
- raise(message)
13
- end
6
+ lines
7
+ # case ExAequo::Colorizer.colorize(lines)
8
+ # in {ok: true, result:}
9
+ # result
10
+ # in {ok: false, message:}
11
+ # raise(message)
12
+ # end
14
13
  end
15
14
 
16
15
  def putsc(lines, device: $stdout) = device.puts(col(lines))
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: awesome_print
@@ -84,8 +84,10 @@ files:
84
84
  - lib/rmux/compiler/checker.rb
85
85
  - lib/rmux/data.rb
86
86
  - lib/rmux/data/built_in.rb
87
+ - lib/rmux/data/common/window_commands.rb
87
88
  - lib/rmux/data/helper.rb
88
89
  - lib/rmux/data/window.rb
90
+ - lib/rmux/data/window/pane.rb
89
91
  - lib/rmux/runner.rb
90
92
  - lib/rmux/tmux.rb
91
93
  - lib/tools/color.rb
@@ -108,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  - !ruby/object:Gem::Version
109
111
  version: '0'
110
112
  requirements: []
111
- rubygems_version: 3.6.2
113
+ rubygems_version: 3.6.8
112
114
  specification_version: 4
113
115
  summary: Tmux sessions
114
116
  test_files: []