Skip to content

Commit

Permalink
shell/fish: use completion to suggest commands in savvy run
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed Sep 17, 2024
1 parent b36f284 commit 4853d48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
30 changes: 20 additions & 10 deletions cmd/setup/savvy.fish
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ __savvy_record_prompt



function __savvy_runbook_runner__ --on-event fish_prompt
if test "$SAVVY_CONTEXT" = "run"
set -l run_cmd (savvy internal current)
echo "run_cmd = $run_cmd"
fish_commandline_append "$run_cmd"
commandline -f repaint
end
end


# Initialize variables
set -g SAVVY_COMMANDS ()
set -g SAVVY_RUN_CURR ""
Expand Down Expand Up @@ -152,3 +142,23 @@ function __savvy_record_pre_exec__ --on-event fish_preexec
)
end
end


# Trigger completion on empty command line
# Refer to shell/fish.go for triggering completion
function __savvy_run_completion__ --description "Complete the current command in a runbook"
if not test "$SAVVY_CONTEXT" = "run"
return
end

set -l run_cmd (savvy internal current)
echo $cmd
set -l cmd (commandline -o)

if test -z "$cmd"
# Completions for empty command line
echo $run_cmd
return
end
end

3 changes: 3 additions & 0 deletions shell/fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (f *fish) SpawnHistoryExpander(ctx context.Context) (*exec.Cmd, error) {

const fishRunRunbookScript = `
if not functions -q __savvy_run_pre_exec__
or not functions -q __savvy_run_completion__
set_color red
echo " Your shell is not configured to use Savvy. Please run the following commands: "
set_color normal
Expand All @@ -125,6 +126,8 @@ if not functions -q __savvy_run_pre_exec__
exit 1
end
complete -c '' -f -a "(__savvy_run_completion__)"
echo
echo "Type 'exit' or press 'ctrl+d' to stop running."
echo
Expand Down

0 comments on commit 4853d48

Please sign in to comment.