Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions conf.d/done.fish
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,29 @@ end
function __done_is_tmux_window_active
set -q fish_pid; or set -l fish_pid %self

# find the outermost process within tmux
# ppid != "tmux" -> pid = ppid
# ppid == "tmux" -> break
# Find the tmux PID that is the parent of the fish process
set tmux_fish_pid $fish_pid
while set tmux_fish_ppid (ps -o ppid= -p $tmux_fish_pid | string trim)
and ! string match -q "tmux*" (basename (ps -o command= -p $tmux_fish_ppid))
while true
if test -e /proc/$tmux_fish_pid/status
# awk is used instead of ps with -o ppid= because the latter is not
# supported by busybox
set tmux_fish_ppid (awk '/PPid:/ {print $2}' /proc/$tmux_fish_pid/status)
set tmux_fish_ppid_cmd_full (busybox ps | awk "{if (\$1 == $tmux_fish_ppid) print \$NF}")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@154pinkchairs you are using busybox in this line, but as far as I understand it is not available in every system. What's the idea?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yup, my idea was just to have the script work with both, must've missed it

Copy link
Copy Markdown
Owner

@franciscolourenco franciscolourenco Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you like to work on alternative? The existing function is error prone and I will have to choose one of the proposed options. This doesn't sound bad if it also covers the other edge cases.

set tmux_fish_ppid_cmd (string split -m 1 / $tmux_fish_ppid_cmd_full)[-1]
else
break
end

if string match -q "tmux*" $tmux_fish_ppid_cmd
break
end

# If the parent is not tmux, keep looking
set tmux_fish_pid $tmux_fish_ppid
end

# tmux session attached and window is active -> no notification
# all other combinations -> send notification
# Check if the tmux session is attached and the window is active
# if so, the tmux window should be considered active
tmux list-panes -a -F "#{session_attached} #{window_active} #{pane_pid}" | string match -q "1 1 $tmux_fish_pid"
end

Expand Down