Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
make kill/pkill completions more robust (#3200)
Someone running fish in an unusual locale reported that an `assert()` was firing when they typed `pkill c`. I traced it to two bugs. First, the __fish_make_completion_signals command was producing a weird result. Second, the builtin `complete` command wasn't adequately verifying its arguments. Fixes #3129
- Loading branch information
Kurtis Rader
committed
Jul 8, 2016
1 parent
2f0cb2a
commit 14c7cfa
Showing
4 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
function __fish_make_completion_signals --description 'Make list of kill signals for completion' | ||
set -q __kill_signals; and return 0 | ||
set -q __kill_signals | ||
and return 0 | ||
|
||
if kill -L ^/dev/null >/dev/null | ||
# Some systems use the GNU coreutils kill command where `kill -L` produces an extended table | ||
# format that looks like this: | ||
# | ||
# 1 HUP Hangup: 1 | ||
# 2 INT Interrupt: 2 | ||
# | ||
# The procps `kill -L` produces a more compact table. We can distinguish the two cases by | ||
# testing whether it supports `kill -t`; in which case it is the coreutils `kill` command. | ||
if kill -t ^/dev/null >/dev/null | ||
# Posix systems print out the name of a signal using 'kill -l SIGNUM'. | ||
complete -c kill -s l --description "List names of available signals" | ||
for i in (seq 31) | ||
set -g __kill_signals $__kill_signals $i" "(kill -l $i | tr '[:lower:]' '[:upper:]') | ||
end | ||
else | ||
# Debian and some related systems use 'kill -L' to write out a numbered list | ||
# of signals. Use this to complete on both number _and_ on signal name. | ||
complete -c kill -s L --description "List codes and names of available signals" | ||
set -g __kill_signals (kill -L | sed -e 's/\([0-9][0-9]*\) *\([A-Z,0-9][A-Z,0-9]*\)/\1 \2\n/g;s/ +/ /g' | sed -e 's/^ \+//' | __fish_sgrep -E '^[^ ]+') | ||
else | ||
# Posix systems print out the name of a signal using 'kill -l | ||
# SIGNUM', so we use this instead. | ||
complete -c kill -s l --description "List names of available signals" | ||
for i in (seq 31) | ||
set -g __kill_signals $__kill_signals $i" "(kill -l $i) | ||
set -g __kill_signals | ||
kill -L | sed -e 's/^ //; s/ */ /g; y/ /\n/' | while read -l signo | ||
test -z "$signo" | ||
and break # the sed above produces one blank line at the end | ||
read -l signame | ||
set -g __kill_signals $__kill_signals "$signo $signame" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
complete: -o requires a non-empty string | ||
complete: -d requires a non-empty string | ||
complete: -l requires a non-empty string | ||
complete: -s requires a non-empty string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters