mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-09 03:51:20 -03:00
bg: deduplicate job argument
"bg %1" of a pipline prints the same line twice because it tries to background the same job twice. This doesn't make sense and other builtins like "disown" already deduplicate, so do the same. Unfortunately we can't use the same approach as "disown" because we can't hold on to references to job, since we're modifying the job list.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// Implementation of the bg builtin.
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::proc::Pid;
|
||||
|
||||
use super::prelude::*;
|
||||
@@ -97,9 +99,12 @@ pub fn bg(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> Built
|
||||
|
||||
// Background all existing jobs that match the pids.
|
||||
// Non-existent jobs aren't an error, but information about them is useful.
|
||||
let mut seen = HashSet::new();
|
||||
for pid in pids {
|
||||
if let Some((job_pos, _job)) = parser.job_get_with_index_from_pid(pid) {
|
||||
send_to_bg(parser, streams, cmd, job_pos)?;
|
||||
if let Some((job_pos, job)) = parser.job_get_with_index_from_pid(pid) {
|
||||
if seen.insert(&*job as *const _) {
|
||||
send_to_bg(parser, streams, cmd, job_pos)?;
|
||||
}
|
||||
} else {
|
||||
streams
|
||||
.err
|
||||
|
||||
@@ -17,3 +17,11 @@ isolated-tmux capture-pane -p
|
||||
# CHECK: fish: Job 1, 'sleep 0.5 &' has ended
|
||||
# (I've seen this print " world", I guess it depends on tmux version and how big it thinks the terminal is)
|
||||
# CHECK: {{.*}} world
|
||||
|
||||
isolated-tmux send-keys C-u C-l "sleep 3 | cat &" Enter "bg %1" Enter
|
||||
tmux-sleep
|
||||
isolated-tmux capture-pane -p | string match -v '*has stopped*'
|
||||
# CHECK: prompt 0> sleep 3 | cat &
|
||||
# CHECK: prompt 0> bg %1
|
||||
# CHECK: Send job 1 'sleep 3 | cat &' to background
|
||||
# CHECK: prompt 1>
|
||||
|
||||
Reference in New Issue
Block a user