-
Notifications
You must be signed in to change notification settings - Fork 591
Expand file tree
/
Copy pathcheckBashCompletion.sh
More file actions
executable file
·27 lines (22 loc) · 1.12 KB
/
checkBashCompletion.sh
File metadata and controls
executable file
·27 lines (22 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash
command=$1
expected=$2
echo -e "Checking completion for command '$command'..."
# Send command as a character stream, followed by two tab characters, into an interactive bash shell.
# Also note the 'y' which responds to the possible Bash question "Display all xxx possibilities? (y or n)".
# Bash produces the autocompletion output on stderr, so redirect that to stdout.
# The sed bit captures the lines between Header and Footer (used as output delimiters).
# The first grep removes the "Display all" message (that is automatically answered to "y" by the script).
# The last grep filters the output to lines containing the expected result.
COMPLETE_OUTPUT=$(echo if false\; then "Header"\; $command$'\t'$'\t'y\; "Footer" fi | bash -i 2>&1 | sed -n '/Header/{:a;n;/Footer/q;p;ba}' | grep -v ^'Display all ')
echo -e "\nCompletion output:\n"
echo -e "$COMPLETE_OUTPUT"
echo -e "\n"
FILTERED_COMPLETE_OUTPUT=$(echo "$COMPLETE_OUTPUT" | grep "$expected")
if [ -z "$FILTERED_COMPLETE_OUTPUT" ]; then
echo -e "Completion output does not contains '$expected'."
exit 1
else
echo -e "Completion output contains '$expected'."
exit 0
fi