Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bash completions #1721

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ jobs:

- name: Package binaries
if: (github.event_name == 'release')
run: zip alr-bin-linux.zip bin/alr LICENSE.txt
run: |
echo 'sudo cp -r bin share /usr/local/' > INSTALL.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have a proper INSTALL.md file a bit more fleshed out, where this command is not just given but also explained. Some people may prefer to use another prefix not requiring sudo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make this Linux-specific or even distro specific? I believe that where to put Bash completion files is a bit distro-dependent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be found automatically? Otherwise I don't think we want to manually maintain such a thing. We can explain in the INSTALL.md file that the given structure is for Debian and should be tweaked if needed. Also yes, I think the INSTALL.md should make clear this is only for Unix-like, and that there's a Windows installer.

zip alr-bin-linux.zip bin/alr share/bash-completion/completions/alr LICENSE.txt INSTALL.md

- name: Retrieve upload URL for the release
if: (github.event_name == 'release')
Expand Down
39 changes: 37 additions & 2 deletions scripts/alr-completion.bash → share/bash-completion/completions/alr
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,43 @@ else
fi
alr settings --global --set index.auto_update 0

# Commands/Topics: all line-first words not starting with capital letter, after # COMMANDS
_alr_commands=$(alr | grep COMMANDS -A 99 | awk '{print $1}' | grep -v '[[:upper:]]' | xargs)
# The help output is roughly structured into sections like so:
# SECTION_NAME_1
# Subsection
# word description
#
# Note that the section names are in ALL_CAPS and the subsection names start
# with a capital letter. The good stuff is the lowercase words in the COMMANDS and ALIASES sections

# First, we collect all commands (words not starting with an uppercase letter) in the COMMANDS section.
# We start matching on the line "COMMANDS" and collect all first words in lines that don't start with a
# capital letter. We stop when we find a line comprised of entirely UPPERCASE letters, which delimits
# the start of another section.
#
# Because Awk range matches are inclusive, and the end pattern would also match the start pattern,
# we have to add a bit of ugliness.

_alr_commands=$(alr | awk '
$0 == "COMMANDS", ($0 ~ /^[A-Z]+$/ && $0 != "COMMANDS") {
if ($0 == "COMMANDS" || $1 ~ /^[A-Z]/ || !NF)
skip
else
print $1
}
')

_alr_commands+=' '

# Now do the same, but for the ALIASES section.

_alr_commands+=$(alr | awk '
$0 == "ALIASES", ($0 ~ /^[A-Z]+$/ && $0 != "ALIASES") {
if ($0 == "ALIASES" || $1 ~ /^[A-Z]/ || !NF)
skip
else
print $1
mosteo marked this conversation as resolved.
Show resolved Hide resolved
}
')

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