From 0bd94fb9935600c069897e2e8ddaffe75343529e Mon Sep 17 00:00:00 2001 From: Mumumu <30195921+Mumumu4@users.noreply.github.com> Date: Tue, 25 Jun 2024 21:34:06 +0800 Subject: [PATCH] Fix nftables completion: when object name contains its type name, the completion may mass up E.g. ``` table inet foo { chain my_chain { jump my_chain2 } chain my_chain2 { } } ``` `nft delete chain inet foo ` get ``` handle -- address chain by handle my_chain2 -- (handle 31) my_chain -- (handle 30) \t\tjump my_chain2 # handle 33 ``` the last line in the completion output is not wanted. --- src/_nftables | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_nftables b/src/_nftables index c891ead..9dd0b68 100644 --- a/src/_nftables +++ b/src/_nftables @@ -468,7 +468,7 @@ _nft_object(){ #$3:object type (chain/set/map/flowtable/ct helper/counter/quota/meter) #$4:include 'handle'? local objects=( ${(f)"$(_call_program -p objects nft -a list table $1 $2 2>/dev/null\ - | grep ""\\s\*$3"" | sed 's/\s*'"$3"' // ;s/ { # \(.*\)/:(\1)/' )"} ) + | grep ""\^\\s\*$3"" | sed 's/\s*'"$3"' // ;s/ { # \(.*\)/:(\1)/' )"} ) if $4 ;then objects+=( "handle:address $3 by handle") fi @@ -481,7 +481,7 @@ _nft_object_handle(){ #$2:table #$3:object type (chain/set/ct helper/counter/quota) local handles=( ${(f)"$(_call_program -p handles nft -a list table $1 $2 2>/dev/null\ - | grep ""\\s\*$3"" | sed 's/\s*'"$3"' // ;s/ { # handle// ;s/\(\S*\) \(\S*\)/\2:\1/' )"} ) + | grep ""\^\\s\*$3"" | sed 's/\s*'"$3"' // ;s/ { # handle// ;s/\(\S*\) \(\S*\)/\2:\1/' )"} ) _describe -t handles "$3-handle" handles }