pi-background 0.2.0 → 0.2.1

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.
@@ -45,6 +45,14 @@ function summary(job: Job): string {
45
45
  return `${job.id} [${state}, ${elapsed(job)}] ${job.command}\n log: ${job.log}`;
46
46
  }
47
47
 
48
+ /** The part of a command worth showing: its first line, without a leading cd and with a script path shortened to its name. */
49
+ function shownCommand(command: string): string {
50
+ return command
51
+ .split("\n")[0]
52
+ .replace(/^\s*(cd\s+("[^"]*"|'[^']*'|\S+)\s*(&&|;)\s*)+/, "")
53
+ .replace(/^\S*\/(?=[^\s/]+(\s|$))/, "");
54
+ }
55
+
48
56
  /** True when a command starts a job with a bare & (not &&, 2>&1, &> or |&). */
49
57
  function startsBackgroundJob(command: string): boolean {
50
58
  return /&/.test(command.replace(/&&|[0-9]*>&[0-9-]*|&>>?|\|&/g, ""));
@@ -120,10 +128,10 @@ export default function (pi: ExtensionAPI) {
120
128
  render(width: number) {
121
129
  const live = running();
122
130
  const lines = live.slice(0, MAX_SHOWN_JOBS).map((job) => {
123
- const command = job.command.split("\n")[0];
131
+ const command = shownCommand(job.command);
124
132
  const text =
125
133
  theme.fg("accent", " ⏵ ") +
126
- theme.fg("toolTitle", `${job.id} ${command.length > 40 ? `${command.slice(0, 39)}…` : command}`) +
134
+ theme.fg("toolTitle", `${job.id} ${command.length > 50 ? `${command.slice(0, 49)}…` : command}`) +
127
135
  theme.fg("dim", ` · ${elapsed(job)}${jobsLine() === "full" && job.lastLine ? ` · ${job.lastLine}` : ""}`);
128
136
  return truncateToWidth(text, width);
129
137
  });
@@ -173,6 +181,7 @@ export default function (pi: ExtensionAPI) {
173
181
  "After bg_run, continue with independent work or end your turn; a message with the exit code and log tail arrives automatically when the job exits, so never sleep, poll or tail the log to wait for it.",
174
182
  "Keep using bash for quick commands whose output you need right away, such as git, ls, cat, grep, find, file inspection and short checks.",
175
183
  "To react when a bg_run job prints something specific while it keeps running (a server is ready, an epoch finished, an error appeared), pass wake_on with a regex instead of polling.",
184
+ "Don't redirect a bg_run command's output to a file (> file, 2>&1, nohup): bg_run already saves all of it to the job's log, and redirecting hides the job's progress from the user and from wake_on. If the output should be kept, tell the user where the job's log is.",
176
185
  "Use bg_status to check progress of a bg_run job and bg_kill to stop one.",
177
186
  `bash commands time out after ${BASH_DEFAULT_TIMEOUT / 60} minutes unless you pass timeout (at most ${BASH_MAX_TIMEOUT / 60} minutes); run anything that may take longer with bg_run instead.`,
178
187
  "Unless the user explicitly asks for that bash command, never wait, poll or sleep in bash (while/until loops with sleep, watch, repeated status checks), not even as part of a larger command; start the wait with bg_run and pass wake_on to be woken when the awaited output appears.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-background",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "author": "Thomas van Dongen",
6
6
  "type": "module",