2

Is there any way to enable arrow keys selection for the kill command in zsh?

E.g.

$ kill <TAB>

gives me a list of all currently running processes, and I can then use arrow keys to select a specific one.

However, when I do:

$ kill foo<TAB>

I get a list of all processes with fooin the name, but I cannot select a specific one from the list via arrow keys.

I've tried looking at the compdef file for kill but am not familiar enough with how the zsh completion system works to understand what needs to be changed in order for it to work.

In case it is of any help, here is my current compdef for kill, at least I assume it is. The file location on my system is: /usr/share/zsh/functions/Completion/Zsh/_kill

#compdef kill

local curcontext="$curcontext" line state ret=1
typeset -A opt_args

_arguments -C \
  '(-s -l 1)-n[specify signal number]:signal number' \
  '(-n -l 1)-s[specify signal name]:signal:_signals -s' \
  '(-n -s)-l[list signal names or numbers of specified signals]:*:signal:_signals' \
  '(-n -s -l)1::signal:_signals -p -s' \
  '*:processes:->processes' && ret=0
  
if [[ -n "$state" ]]; then
  local pgrp='process-groups:: _wanted '
  [[ -n "$opt_args[(i)-[ns]]${${(@)line:#--}}" && -prefix - ]] && pgrp+='-x '
  pgrp+="process-groups expl 'process-group' compadd - 0"
  _alternative \
    'processes:: _pids' \
    'jobs:: _jobs -t' $pgrp && ret=0
fi

return ret
rtur
  • 165
  • 9

2 Answers2

0

My Zsh Autocomplete plugin adds arrow keys selection for all commands and configures Zsh's completion system so that this works correctly for your kill foo case, too.

Marlon Richert
  • 5,250
  • 1
  • 18
  • 27
0

add zstyle ':completion:*' menu select to .zshrc.

Nelson Lee
  • 29
  • 2
  • 1