hiiro 0.1.371 → 0.1.372
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/docs/h-bg.md +1 -1
- data/lib/hiiro/background.rb +26 -12
- data/lib/hiiro/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf0a697dfb88ddd554983d6eed9f0419087da31726ffa0fdade260b393eed0fc
|
|
4
|
+
data.tar.gz: dcf0ce065b625cd1a30b7cc8bf03bbf708be1d9068df677d31e714f332d0a6c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 262c177d9b2296634b9d23fad53cd5df8e98d38f1230035f55ed9e209e5d918c730ea2bf6bb15226c1103db7902fe43e000d961eb53730861d5e4146d40b1e0f
|
|
7
|
+
data.tar.gz: 4256ab7812cad7cf221bd1d66b2f645ce9d1adb63c561b07fe8a4c30256fb1093120d3271935217b4369c31639cf7e053c1fd5a6b45f38f0e29f479e28a6ae84
|
data/CHANGELOG.md
CHANGED
data/docs/h-bg.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Run commands in unfocused Herdr tabs with command history tracking.
|
|
4
4
|
|
|
5
|
-
Inside Herdr, commands run in the `h-bg` workspace,
|
|
5
|
+
Inside Herdr, commands run in the `h-bg` workspace. Each command reuses the first pane there that is sitting at an idle shell prompt (no agent and no foreground process, as reported by `herdr pane process-info`) and only opens a new unfocused tab when every pane is busy, so the workspace holds at most as many tabs as jobs that ran at the same time. Outside Herdr, Hiiro falls back to a detached local process. History is stored at `~/.config/hiiro/bg-history.txt`.
|
|
6
6
|
|
|
7
7
|
## Synopsis
|
|
8
8
|
|
data/lib/hiiro/background.rb
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
|
+
require 'shellwords'
|
|
2
|
+
|
|
1
3
|
class Hiiro
|
|
2
4
|
module Background
|
|
3
5
|
WORKSPACE = 'h-bg'
|
|
4
6
|
|
|
5
|
-
# Run cmd asynchronously. Inside Herdr,
|
|
6
|
-
# h-bg workspace
|
|
7
|
-
#
|
|
7
|
+
# Run cmd asynchronously. Inside Herdr, reuses an idle shell pane in the
|
|
8
|
+
# h-bg workspace and only opens a new unfocused tab when every pane there is
|
|
9
|
+
# busy, so the workspace never grows past the number of concurrent jobs.
|
|
10
|
+
# Outside Herdr, falls back to a detached spawn.
|
|
8
11
|
#
|
|
9
12
|
# dir: optional directory to cd into before running the command.
|
|
10
|
-
def self.run(*cmd, dir: nil)
|
|
13
|
+
def self.run(*cmd, dir: nil, client: nil)
|
|
11
14
|
if inside_herdr?
|
|
12
|
-
client
|
|
15
|
+
client ||= Hiiro::Herdr.client
|
|
13
16
|
workspace = ensure_workspace(client)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
command = cmd.shelljoin
|
|
18
|
+
command = "cd #{dir.shellescape} && #{command}" if dir
|
|
19
|
+
if (pane = idle_pane(client, workspace))
|
|
20
|
+
client.run_in_pane(pane.id, command)
|
|
21
|
+
else
|
|
22
|
+
client.new_tab(
|
|
23
|
+
name: cmd.first.to_s,
|
|
24
|
+
workspace: workspace,
|
|
25
|
+
start_directory: dir,
|
|
26
|
+
command: command,
|
|
27
|
+
focus: false
|
|
28
|
+
)
|
|
29
|
+
end
|
|
21
30
|
else
|
|
22
31
|
spawn_opts = dir ? { chdir: dir } : {}
|
|
23
32
|
Process.detach(spawn(*cmd, **spawn_opts))
|
|
@@ -33,5 +42,10 @@ class Hiiro
|
|
|
33
42
|
def self.ensure_workspace(client = Hiiro::Herdr.client)
|
|
34
43
|
client.find_workspace(WORKSPACE) || client.new_workspace(WORKSPACE, focus: false)
|
|
35
44
|
end
|
|
45
|
+
|
|
46
|
+
# A pane in the workspace sitting at a shell prompt with no foreground command.
|
|
47
|
+
def self.idle_pane(client, workspace)
|
|
48
|
+
client.panes(workspace: workspace).find { |pane| pane.agent.nil? && pane.foreground_command.nil? }
|
|
49
|
+
end
|
|
36
50
|
end
|
|
37
51
|
end
|
data/lib/hiiro/version.rb
CHANGED