Skip to content

Commit

Permalink
Merge pull request #1799 from obriat/issue/1798-bash-complete
Browse files Browse the repository at this point in the history
Fix bash completion
  • Loading branch information
lmakarov committed Apr 2, 2024
2 parents a869e32 + 03a9ce2 commit 50c4bc0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
13 changes: 10 additions & 3 deletions bin/fin
Original file line number Diff line number Diff line change
Expand Up @@ -2496,7 +2496,14 @@ bash_comp_words ()
local custom_commands

for cmd_name in $(ls "$project_commands_path" 2>/dev/null | tr "\n" " "); do
custom_commands+=" $cmd_name"
if [ -d "$project_commands_path/$cmd_name" ]; then
for sub_cmd_name in $(ls "$project_commands_path/$cmd_name" 2>/dev/null | tr "\n" " "); do
[[ -f "$project_commands_path/$cmd_name/$sub_cmd_name" ]] &&
custom_commands+=" $cmd_name/$sub_cmd_name"
done
else
custom_commands+=" $cmd_name"
fi
done

for cmd_name in $(ls "$project_addons_path" 2>/dev/null); do
Expand Down Expand Up @@ -4957,7 +4964,7 @@ update_config_files ()
install_bash_autocomplete ()
{
local destination="$FIN_AUTOCOMPLETE_PATH"
tee "$destination" >/dev/null <<'EOF'
sudo tee "$destination" >/dev/null <<'EOF'
_docksal_completion()
{
local cur=${COMP_WORDS[COMP_CWORD]} #current word part
Expand All @@ -4974,7 +4981,7 @@ complete -o bashdefault -o default -F _docksal_completion fin
EOF
if_failed "Failed to write file to $destination"
echo-green "Script saved to $destination"
chmod +x "$destination"
sudo chmod +x "$destination"

SOURCE_FILE=".bash_profile"
grep -q "$destination" "$HOME/$SOURCE_FILE"
Expand Down
5 changes: 5 additions & 0 deletions docs/content/fin/custom-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,8 @@ fin=`which fin`

Check the commands directory (examples/.docksal/commands) located in the [Docksal project](https://github.com/docksal/docksal)
or [read the blog post on writing custom commands](https://blog.docksal.io/writing-fin-init-and-other-docksal-custom-commands-dc103b2747cd).

## Enable bash autocompletion

Bash autocompletion could be enable by executing: `fin update ----bash-complete`.
Then, type `fin` and press the TAB key twice to display commands available in the current dir.
8 changes: 7 additions & 1 deletion docs/content/fin/fin-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ Update Docksal system components to the latest stable version
Usage: update
Options:
DOCKSAL_VERSION=develop fin update Update Docksal to the latest development version
DOCKSAL_VERSION=develop fin update Update Docksal to the latest development version
--system-images Update system images
--project-images Update project images
--self Update fin executbale
--tools Update tools
--stack Update config files
--bash-complete Install bash autocomplete
```

0 comments on commit 50c4bc0

Please sign in to comment.