From 245e9e1d48f099c99ec0ec0d016ab4829c8ac578 Mon Sep 17 00:00:00 2001 From: Kadin Sayani Date: Thu, 5 Sep 2024 14:51:50 -0600 Subject: [PATCH] snapcraft: Set up completer for snap Signed-off-by: Kadin Sayani --- snapcraft.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/snapcraft.yaml b/snapcraft.yaml index c50cf3b5..1d8384b4 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1448,7 +1448,14 @@ parts: # Setup bash completion mkdir -p "${CRAFT_PART_INSTALL}/etc/bash_completion.d/" - "${CRAFT_PART_INSTALL}/bin/lxc" completion bash > "${CRAFT_PART_INSTALL}/etc/bash_completion.d/snap.lxd.lxc" + # Snapd requires the unaliased command `lxd.lxc` to be supplied as the first command for completion to be detected + set_cmds='s/^\s*complete.*__start_lxc /&lxd.lxc /' + # When executed by Snapd, the COLUMNS shell value is unset, so use $(tput cols) instead + set_cols='s/COLUMNS/$(tput cols)/' + # Modify requestComp variable to use lxc based on context ($SNAP/bin/lxc in Snap environment) + set_request_comp='s|requestComp="${words\[0\]} __complete ${args\[\*\]}"|requestComp="/snap/lxd/current/bin/lxc __complete ${args[*]}"|' + # Generate completions script + "${CRAFT_PART_INSTALL}/bin/lxc" completion bash | sed -e "${set_cmds}" -e "${set_cols}" -e "${set_request_comp}" > "${CRAFT_PART_INSTALL}/etc/bash_completion.d/snap.lxd.lxc" organize: usr/bin/: bin/ usr/lib/: lib/