Skip to content

Commit

Permalink
snapcraft: Fix LXD snap bash completions (#674)
Browse files Browse the repository at this point in the history
Fixes canonical/lxd#14635,
canonical/lxd#14690 and
canonical/lxd#14648.

This PR changes the permissions, location, and file extension of the
`lxc` bash completions script to ensure correct execution. The
`bash-completions` package is also added to the snap stage packages.
  • Loading branch information
tomponline authored Jan 7, 2025
2 parents ac86a01 + 8fdccb7 commit 52f1e13
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ apps:

lxc:
command: commands/lxc
completer: etc/bash_completion.d/snap.lxd.lxc
completer: lxc-completer.sh
plugs:
- lxd-support
- system-observe
Expand Down Expand Up @@ -1470,9 +1470,10 @@ parts:
# 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[*]}"|'
set_request_comp='s|requestComp="${words\[0\]} __complete ${args\[\*\]}"|requestComp="/snap/lxd/current/commands/lxc __complete ${args[*]}"|'
# Generate completions script
"${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"
"${CRAFT_PART_INSTALL}/bin/lxc" completion bash | sed -e "${set_cmds}" -e "${set_cols}" -e "${set_compopt}" -e "${set_request_comp}" > "${CRAFT_PART_INSTALL}/lxc-completer.sh"
chmod +x "${CRAFT_PART_INSTALL}/lxc-completer.sh"
organize:
usr/bin/: bin/
usr/lib/: lib/
Expand All @@ -1493,7 +1494,7 @@ parts:

- lib/*/libidn.so.*

- etc/bash_completion.d/snap.lxd.lxc
- lxc-completer.sh

- share/lxd-documentation*
- share/misc/pci.ids
Expand Down

0 comments on commit 52f1e13

Please sign in to comment.