From 00112ee146223fb46c228caa33bd1a309ea7830f Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Thu, 21 Nov 2024 20:31:36 -0500 Subject: [PATCH 1/2] snapcraft: hardcode support for compopt to fix bash completion Reported-by: Kadin Sayani Signed-off-by: Simon Deziel (cherry picked from commit d51c247078dd92254f4b28d84af29abc3410bb2c) --- snapcraft.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snapcraft.yaml b/snapcraft.yaml index b9101095..3ed287d1 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1531,10 +1531,12 @@ parts: 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)/' + # When executed by snapd, the `compopt` support detection doesn't work so fake that it is always `builtin` + set_compopt='s|$(type -t compopt)|"builtin"|' # 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" + "${CRAFT_PART_INSTALL}/bin/lxc" completion bash | sed -e "${set_cmds}" -e "${set_cols}" -e "${set_compopt}" -e "${set_request_comp}" > "${CRAFT_PART_INSTALL}/etc/bash_completion.d/snap.lxd.lxc" organize: usr/bin/: bin/ usr/lib/: lib/ From 6a908202a8ee34c63b2ee53782269de5391bd50c Mon Sep 17 00:00:00 2001 From: Simon Deziel Date: Thu, 21 Nov 2024 20:41:14 -0500 Subject: [PATCH 2/2] snapcraft: call `tput cols` only once during completion Signed-off-by: Simon Deziel (cherry picked from commit 55c4560d07d2646e6df67385da730934365d35d2) --- snapcraft.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snapcraft.yaml b/snapcraft.yaml index 3ed287d1..9dd5bafa 100644 --- a/snapcraft.yaml +++ b/snapcraft.yaml @@ -1529,8 +1529,8 @@ parts: mkdir -p "${CRAFT_PART_INSTALL}/etc/bash_completion.d/" # 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)/' + # When executed by snapd, the COLUMNS shell value is unset, so use $(tput cols) instead + set_cols='s/# $COLUMNS.*/COLUMN="$(tput cols)" \# store the current shell width./' # When executed by snapd, the `compopt` support detection doesn't work so fake that it is always `builtin` set_compopt='s|$(type -t compopt)|"builtin"|' # Modify requestComp variable to use lxc based on context ($SNAP/bin/lxc in Snap environment)