Skip to content

Commit d08f2ef

Browse files
committed
Generate bash_completion file with make, not bootstrap
1 parent e33e629 commit d08f2ef

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
SUBDIRS = src docs
22

3+
dfu_programmer: dfu_completion update-bash-completion.sh src/arguments.c
4+
./update-bash-completion.sh
5+
6+
bash-completion: dfu_programmer
7+
.PHONY: bash-completion
8+
all: bash-completion
9+
310
EXTRA_DIST = bootstrap.sh dfu_completion \
411
fedora/10-dfu-programmer.fdi \
512
fedora/dfu-programmer.spec

bootstrap.sh

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,3 @@ aclocal -I m4
88
autoheader
99
automake --foreign --add-missing --force-missing
1010
autoconf
11-
12-
set +x # Disable echoing of commands
13-
14-
if [ "$(echo `uname`)" = "Linux" ]; then
15-
TARGET_START_LINE=$( grep START_TARGET_LIST_LINE -n src/arguments.c | \
16-
sed "s/^\(.*\):.*/\1/")
17-
TARGET_END_LINE=$( grep END_TARGET_LIST_LINE -n src/arguments.c | \
18-
sed "s/^\(.*\):.*/\1/")
19-
TARGET_INFO=$( sed -n "$TARGET_START_LINE,$TARGET_END_LINE p" src/arguments.c | \
20-
grep "^\s*{ \"" | sed 's/.*"\(.*\)".*,\s*\([xX0-9A-Fa-f]*\)\s*},/\1::\2/' )
21-
22-
DFU_COMP=dfu_programmer
23-
24-
echo \#\ autocomplete\ script > $DFU_COMP
25-
echo "# code sourced from dfu_completion, DO NOT EDIT IN THIS FILE" \
26-
>> $DFU_COMP
27-
echo >> $DFU_COMP
28-
echo -n "TARGET_INFO=\" " >> $DFU_COMP
29-
echo -n $TARGET_INFO >> $DFU_COMP
30-
echo " \"" >> $DFU_COMP
31-
echo >> $DFU_COMP
32-
echo >> $DFU_COMP
33-
34-
cat dfu_completion >> $DFU_COMP
35-
36-
chmod +x $DFU_COMP
37-
38-
#if [ "$(cat /etc/*release | grep DISTRIB_ID | sed 's/DISTRIB_ID=//')" = "Ubuntu" ]]; then
39-
echo "To install tab completion run"
40-
echo " \$ sudo mv $DFU_COMP /etc/bash_completion.d/"
41-
#fi
42-
echo "To use tab completion in this terminal run"
43-
echo " \$ source $DFU_COMP"
44-
fi

update-bash-completion.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# sed - without printing by default (-n)
4+
# Remove lines up to and including the start line, which includes: START_TARGET_LIST_LINE
5+
# Remove lines after and including the end line, which includes: END_TARGET_LIST_LINE
6+
# Get the part between the quotes and the last number
7+
TARGET_INFO=$( sed -n '1,/START_TARGET_LIST_LINE/d; /END_TARGET_LIST_LINE/,$d; s/.*"\(.*\)".*,\s*\([xX0-9A-Fa-f]*\)\s*},/\1::\2/p' src/arguments.c )
8+
9+
# Output file
10+
DFU_COMP=dfu_programmer
11+
12+
# Write the header with the TARGET_INFO
13+
cat << EOF > $DFU_COMP
14+
# autocomplete script
15+
# code sourced from \`dfu_completion\`
16+
# DO NOT EDIT IN THIS FILE
17+
18+
TARGET_INFO="$TARGET_INFO"
19+
20+
EOF
21+
22+
# Remove everything up to and including the first empty line
23+
sed 1,/^\$/d dfu_completion >> $DFU_COMP
24+
25+
chmod +x $DFU_COMP
26+
27+
#if [ "$(cat /etc/*release | grep DISTRIB_ID | sed 's/DISTRIB_ID=//')" = "Ubuntu" ]]; then
28+
echo "To install tab completion run"
29+
echo " \$ sudo mv $DFU_COMP /etc/bash_completion.d/"
30+
#fi
31+
echo "To use tab completion in this terminal run"
32+
echo " \$ source $DFU_COMP"

0 commit comments

Comments
 (0)