mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Rewrite __fish_complete_proc
- No longer uses sed, sort, uniq, uname - Stop doing too-clever filtering (e.g. the kernel thread stuff never - really worked) - Don't truncate for all OSen, instead just use the (correctly - truncated) comm field.
This commit is contained in:
parent
3a835ebd61
commit
60fa9da3a7
2 changed files with 7 additions and 50 deletions
|
@ -1,9 +1,6 @@
|
|||
|
||||
function __fish_complete_pgrep -d 'Complete pgrep/pkill' --argument-names cmd
|
||||
# Some implementations only track the first X characters of a process name
|
||||
# (with linux having the lowest X = 15).
|
||||
# Just cut at 15 for all, and put the rest in the description.
|
||||
complete -c $cmd -xa '(__fish_complete_proc | string replace -r "(.{15})(.+)" "\$1\\t\$2")'
|
||||
complete -c $cmd -xa '(__fish_complete_proc)'
|
||||
complete -c $cmd -s f -d 'Match pattern against full command line'
|
||||
complete -c $cmd -s g -d 'Only match processes in the process group' -xa '(__fish_complete_list , __fish_complete_groups)'
|
||||
complete -c $cmd -s G -d "Only match processes whose real group ID is listed. Group 0 is translated into $cmd\'s own process group" -xa '(__fish_complete_list , __fish_complete_groups)'
|
||||
|
|
|
@ -1,47 +1,7 @@
|
|||
function __fish_complete_proc --description 'Complete by list of running processes'
|
||||
# Our function runs ps, followed by a massive list of commands passed to sed
|
||||
set -l ps_cmd
|
||||
set -l sed_cmds
|
||||
if test (uname) = Linux
|
||||
# comm and ucomm return a truncated name, so parse it from the command line field,
|
||||
# which means we have to trim off the arguments.
|
||||
# Unfortunately, it doesn't seem to escape spaces - so we can't distinguish
|
||||
# between the command name, and the first argument. Still, processes with spaces
|
||||
# in the name seem more common on OS X than on Linux, so prefer to parse out the
|
||||
# command line rather than using the stat data.
|
||||
# If the command line is unavailable, you get the stat data in brackets - so
|
||||
# parse out brackets too.
|
||||
set ps_opt -A -o command
|
||||
|
||||
# Erase everything after the first space
|
||||
set -a sed_cmds 's/ .*//'
|
||||
|
||||
# Erases weird stuff Linux gives like kworker/0:0
|
||||
set -a sed_cmds 's|/[0-9]:[0-9]]$||g'
|
||||
|
||||
# Retain the last path component only
|
||||
set -a sed_cmds 's|.*/||g'
|
||||
|
||||
# Strip off square brackets. Cute, huh?
|
||||
set -a sed_cmds 's/[][]//g'
|
||||
|
||||
# Erase things that are just numbers
|
||||
set -a sed_cmds 's/^[0-9]*$//'
|
||||
else
|
||||
# OS X, BSD. Preserve leading spaces.
|
||||
set ps_opt axc -o comm
|
||||
|
||||
# Delete parenthesized (zombie) processes
|
||||
set -a sed_cmds '/(.*)/d'
|
||||
end
|
||||
|
||||
# Append sed command to delete first line (the header)
|
||||
set -a sed_cmds '1d'
|
||||
|
||||
# Append sed commands to delete leading dashes and trailing spaces
|
||||
# In principle, commands may have trailing spaces, but ps emits space padding on OS X
|
||||
set -a sed_cmds 's/^-//' 's/ *$//'
|
||||
|
||||
# Run ps, pipe it through our massive set of sed commands, then sort and unique
|
||||
ps $ps_opt | sed '-e '$sed_cmds | sort -u
|
||||
function __fish_complete_proc
|
||||
# "comm=" means "print comm field with an empty name", which causes the header to be removed.
|
||||
# On many systems, comm is truncated (e.g. on Linux it's 15 chars),
|
||||
# but that's okay since commands that accept them as argument also only use those (e.g. pgrep).
|
||||
# String removes zombies (ones in parentheses) and padding (macOS adds some apparently).
|
||||
ps -axc -o comm= | string match -rv '\(.*\)' | string trim
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue