Skip to content

Commit 7e6e412

Browse files
committed
Fix Bash completions
The previous completion script was including extra completions that were not actually commands. This commit also moves the completion file and renames it such that on Ubuntu one can simple download the release zip, unpack it, cd into the unpacked directory, and run `cp -r bin share /usr/local` to install with bash-completions in the proper place to get automatically sourced
1 parent 16b060b commit 7e6e412

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

.github/workflows/ci-linux.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ jobs:
6666

6767
- name: Package binaries
6868
if: (github.event_name == 'release')
69-
run: zip alr-bin-linux.zip bin/alr LICENSE.txt
69+
run: |
70+
echo 'sudo cp -r bin share /usr/local/' > INSTALL.md
71+
zip alr-bin-linux.zip bin/alr share/bash-completion/completions/alr LICENSE.txt INSTALL.md
7072
7173
- name: Retrieve upload URL for the release
7274
if: (github.event_name == 'release')
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,43 @@ else
1313
fi
1414
alr settings --global --set index.auto_update 0
1515

16-
# Commands/Topics: all line-first words not starting with capital letter, after # COMMANDS
17-
_alr_commands=$(alr | grep COMMANDS -A 99 | awk '{print $1}' | grep -v '[[:upper:]]' | xargs)
16+
# The help output is roughly structured into sections like so:
17+
# SECTION_NAME_1
18+
# Subsection
19+
# word description
20+
#
21+
# Note that the section names are in ALL_CAPS and the subsection names start
22+
# with a capital letter. The good stuff is the lowercase words in the COMMANDS and ALIASES sections
23+
24+
# First, we collect all commands (words not starting with an uppercase letter) in the COMMANDS section.
25+
# We start matching on the line "COMMANDS" and collect all first words in lines that don't start with a
26+
# capital letter. We stop when we find a line comprised of entirely UPPERCASE letters, which delimits
27+
# the start of another section.
28+
#
29+
# Because Awk range matches are inclusive, and the end pattern would also match the start pattern,
30+
# we have to add a bit of ugliness.
31+
32+
_alr_commands=$(alr | awk '
33+
$0 == "COMMANDS", ($0 ~ /^[A-Z]+$/ && $0 != "COMMANDS") {
34+
if ($0 == "COMMANDS" || $1 ~ /^[A-Z]/ || !NF)
35+
skip
36+
else
37+
print $1
38+
}
39+
')
40+
41+
_alr_commands+=' '
42+
43+
# Now do the same, but for the ALIASES section.
44+
45+
_alr_commands+=$(alr | awk '
46+
$0 == "ALIASES", ($0 ~ /^[A-Z]+$/ && $0 != "ALIASES") {
47+
if ($0 == "ALIASES" || $1 ~ /^[A-Z]/ || !NF)
48+
skip
49+
else
50+
print $1
51+
}
52+
')
1853

1954
# Long global switches
2055
_alr_global_switches=$(alr -h | grep -Eo -- '--[[:alnum:]-]+' | xargs)

0 commit comments

Comments
 (0)