Skip to content

Commit

Permalink
Fix for cobra shell completions (canonical#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomponline authored Sep 12, 2024
2 parents d281c4a + 245e9e1 commit a007c94
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,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/
Expand Down

0 comments on commit a007c94

Please sign in to comment.