fix bash completion of package names for the filter arg
Not all devices can do ls /data/data, so instead use the running process list, which should be guaranteed to be public to all running processes.
The only downside here is that it restricts to running packages. What about using pm list packages -f instead?
I was thinking that restricting it to running packages was actually a feature since that'll make the completion list a lot shorter, and what are the chances of someone wanting to get the logcat of a process that isn't running? I suppose it might be that the process has been totally killed or died somehow in the process of debugging, and that would be annoying that it doesn't show up in the completion.
pm list packages -f gives a big list, including all of the system apps. I think to go that route, it would require grep /data to limit the completion list to filter out the system apps to keep the completion list's signal-to-noise high.
Also, any ideas on whether pm list packages -f is always implemented and runnable without root? When was it added to Android? ps is as close to a guarantee as I can think of with Android.
The package manager has been around since API 1, so presumably the command has as well. And yes it does not require root.
what are the chances of someone wanting to get the logcat of a process that isn't running?
90% of the time I'm starting pidcat before the app I want to observe.
I updated it to use pm list packages -3 to only list the user installed packages, i.e. those in /data. It's been working well for me, but I haven't tried it on anything older than 4.4.2.
In my opinion we should just use adb shell pm list packages without any options, as that will list all installed packages.
Other than that, any plans to merge this?
without -3 there was a lot of pointless noise in the completion, from all the system apps
You are assuming other users don't want to filter for a system app, which we do.
Why is it not merged? I made own implementation with awk for local use:
local apks=$(adb $device_selected shell 'pm list packages -3' 2>/dev/null | awk '
BEGIN {ORS=" "}
$1 ~/package:/ { gsub(/^.*:/,""); gsub(/\r*$/,""); print $1 }')
@JakeWharton any plans on merging this?