lincheney / fzf-tab-completion

Tab completion using fzf
GNU General Public License v3.0
623 stars 40 forks source link

Fix for #70 is not portable to macOS, BSD `ps` is different to Linux `ps` #71

Closed bluz71 closed 1 year ago

bluz71 commented 1 year ago

Hello @lincheney,

Sadly, the fix for #70, this commit, is not portable to macOS.

Basically this code:

        descend_process () {
            printf '%s\n' "$1"
            for pid in $(ps -o pid= --ppid "$1"); do
                descend_process "$pid"
            done
        }
        kill -- $(descend_process "$coproc_pid") 2>/dev/null

GNU ps provides --ppid, but macOS BSD ps does not support that option; this error message results:

ps: illegal option -- -

Would pkill -P <<ppid>> be an alternative? macOS/BSD and GNU Linux both support pkill -P.

Regards.

lincheney commented 1 year ago

will that catch all descendant processes? or just children? Perhaps pgrep -P ... could be a replacement for the ps command? (if you can confirm that does what I think it does on mac; i'm afraid i don't run a mac, so i usually rely on the freebsd man pages for these things, but that's not as good as the real thing)

bluz71 commented 1 year ago

macOS (at least my M1 Macbook) does not have psgrep command. So that is not an option.

I suggest pkill -P since that is available for both Linux and macOS. I understand that it would only kill children, not descendants; though I am not 100% sure.

Can recursion + pkill -P work?

lincheney commented 1 year ago

have you tried pgrep (not psgrep)

lincheney commented 1 year ago

This suggests mac os should have it: https://unix.stackexchange.com/a/100759

bluz71 commented 1 year ago

Yes, macOS has pgrep. Sorry, my bad.

pgrep -P does exist.

lincheney commented 1 year ago

excellent I've pushed up a change to make it use pgrep -P instead https://github.com/lincheney/fzf-tab-completion/commit/745cd038fc9f7e279d95e1d2a1a9b812a7182f5b

bluz71 commented 1 year ago

Sorry for the delayed response, mostly due to timezones.

Many thanks @lincheney, issue is indeed fixed, code runs perfectly on GNU Linux and macOS BSD (and probably all other BSDs as well).

Excellent work, this is a great utility especially for us Bash users who don't have as nice a completion as Zsh; but this really improves my Bash workflow a lot. Thanks!