lincheney / fzf-tab-completion

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

[enhancement] alternative for pgrep not available in bash from git for windows #102

Closed DanSM-5 closed 3 months ago

DanSM-5 commented 4 months ago

I tested the fzf-tab-completion in bash from git for windows (gitbash) and it works fine but after each completion it prints the error

bash: pgrep: command not found

It happens because gitbash does not provide a pgrep binary.

I've taken a look at the fzf-bash-completion.sh file and I noticed that pgrep is used on a single place to get descendant processes (pgrep -P). I polyfilled it with this function for now (not sure if it fully complies with pgrep -P but seems to yield equal results under linux mint, wsl (ubuntu) and gitbash).

  pgrep () {
    # Ignore $1 which is always '-P'
    awk -v ppid="$2" '{ if($3 == ppid) print $2 }' <(ps -ef)
  }

Maybe some support could be added for gitbash. It can be detected like this:

# Cygwin can be added to with 'CYGWIN.+' but I'm unaware if it includes its own pgrep implementation 
if [[ "$(uname)" =~ MINGW.+|MSYS.+ ]]; then
   ... do something for gitbash
fi

or it could be included in the readme in the bash setup section to mention this limitation of gitbash.

lincheney commented 3 months ago

I've replaced the use of pgrep with ps + awk as you've suggested. Seems to work ok for me. https://github.com/lincheney/fzf-tab-completion/commit/2262b9fc6c0635871b90108e81f1537628a89cbb Are you able to give it a try?

DanSM-5 commented 3 months ago

I've tested the fix for a couple of hours two pcs that I have and it is working fine 👍