wg-quick: only bash complete existing interfaces for down
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
		
							parent
							
								
									34337b0906
								
							
						
					
					
						commit
						92feabdd17
					
				@ -4,20 +4,23 @@ _wg_quick_completion() {
 | 
				
			|||||||
	local i a
 | 
						local i a
 | 
				
			||||||
	if [[ $COMP_CWORD -eq 1 ]]; then
 | 
						if [[ $COMP_CWORD -eq 1 ]]; then
 | 
				
			||||||
		COMPREPLY+=( $(compgen -W "up down" -- "${COMP_WORDS[1]}") )
 | 
							COMPREPLY+=( $(compgen -W "up down" -- "${COMP_WORDS[1]}") )
 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	elif [[ $COMP_CWORD -eq 2 ]]; then
 | 
						elif [[ $COMP_CWORD -eq 2 ]]; then
 | 
				
			||||||
		local old_glob="$(shopt -p nullglob)"
 | 
							if [[ ${COMP_WORDS[1]} == up ]]; then
 | 
				
			||||||
		shopt -s nullglob
 | 
								local old_glob="$(shopt -p nullglob)"
 | 
				
			||||||
		for i in /etc/wireguard/*.conf; do
 | 
								shopt -s nullglob
 | 
				
			||||||
			i="${i##*/}"; i="${i%.conf}"
 | 
								for i in /etc/wireguard/*.conf; do
 | 
				
			||||||
			mapfile -t a < <(compgen -W "$i" -- "${COMP_WORDS[2]}")
 | 
									i="${i##*/}"; i="${i%.conf}"
 | 
				
			||||||
 | 
									mapfile -t a < <(compgen -W "$i" -- "${COMP_WORDS[2]}")
 | 
				
			||||||
 | 
									COMPREPLY+=( "${a[@]}" )
 | 
				
			||||||
 | 
								done
 | 
				
			||||||
 | 
								eval "$old_glob"
 | 
				
			||||||
 | 
								mapfile -t a < <(compgen -f -X '!*.conf' -- "${COMP_WORDS[2]}")
 | 
				
			||||||
			COMPREPLY+=( "${a[@]}" )
 | 
								COMPREPLY+=( "${a[@]}" )
 | 
				
			||||||
		done
 | 
								mapfile -t a < <(compgen -d -- "${COMP_WORDS[2]}")
 | 
				
			||||||
		eval "$old_glob"
 | 
								COMPREPLY+=( "${a[@]}" )
 | 
				
			||||||
		mapfile -t a < <(compgen -f -X '!*.conf' -- "${COMP_WORDS[2]}")
 | 
							elif [[ ${COMP_WORDS[1]} == down ]]; then
 | 
				
			||||||
		COMPREPLY+=( "${a[@]}" )
 | 
								COMPREPLY+=( $(compgen -W "$(wg show interfaces)" -- "${COMP_WORDS[2]}") )
 | 
				
			||||||
		mapfile -t a < <(compgen -d -- "${COMP_WORDS[2]}")
 | 
							fi
 | 
				
			||||||
		COMPREPLY+=( "${a[@]}" )
 | 
					 | 
				
			||||||
	fi
 | 
						fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user