Skip to content

Commit

Permalink
work out issues with vendor dirs and color sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed Sep 17, 2024
1 parent 7cf2815 commit 30c9bf1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/setup/savvy.fish
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 44,7 @@ set -g SAVVY_COMMANDS ()
set -g SAVVY_RUN_CURR ""
set -g SAVVY_NEXT_STEP 0

function __savvy_run_pre_exec --on-event fish_preexec
function __savvy_run_pre_exec__ --on-event fish_preexec
if not test "$SAVVY_CONTEXT" = "run"
return
end
Expand Down
39 changes: 24 additions & 15 deletions shell/fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 53,17 @@ else
source "$HOME/.config/fish/conf.d/login.fish"
end
end
`
const fishRecordSetup = `
if not functions -q __savvy_record_pre_exec__
echo (set_color red) "Your shell is not configured to use Savvy. Please run the following commands: " (set_color normal)
set_color red
echo -n "Your recording shell is not configured to use Savvy. Please run the following commands: "
set_color normal
echo
echo (set_color red)"> echo 'savvy init fish | source' >> ~/.config/fish/config.fish"(set_color normal)
echo (set_color red)"> source ~/.config/fish/config.fish"(set_color normal)
set_color red echo "> echo 'savvy init fish | source' >> ~/.config/fish/config.fish" set_color normal
set_color red echo "> source ~/.config/fish/config.fish" set_color normal
exit 1
end
`
const fishRecordSetup = `
echo
echo "Type 'exit' or press 'ctrl d' to stop recording."
`
Expand All @@ -77,7 78,10 @@ func init() {
// Spawn starts a fish shell.
func (f *fish) Spawn(ctx context.Context) (*exec.Cmd, error) {
// Create a temporary file to store the script
tmpDir := os.TempDir()
tmpDir, err := os.MkdirTemp("", "savvy-fish-*")
if err != nil {
return nil, err
}
fishVendorConfDir := filepath.Join(tmpDir, "fish", "vendor_conf.d")
if err := os.MkdirAll(fishVendorConfDir, 0755); err != nil {
return nil, err
Expand All @@ -94,7 98,7 @@ func (f *fish) Spawn(ctx context.Context) (*exec.Cmd, error) {

dataDirs := os.Getenv("XDG_DATA_DIRS")
if dataDirs == "" {
dataDirs = fishVendorConfDir
dataDirs = tmpDir
} else {
dataDirs = strings.Join([]string{dataDirs, fishVendorConfDir}, ":")
}
Expand All @@ -116,16 120,18 @@ 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: "
echo -n " Your shell is not configured to use Savvy. Please run the following commands: "
set_color normal
echo
set_color red
echo "> echo 'savvy init fish | source' >> ~/.config/fish/config.fish"
echo "> source ~/.config/fish/config.fish"
echo
echo -n "> echo 'savvy init fish | source' >> ~/.config/fish/config.fish"
echo -n "> source ~/.config/fish/config.fish"
set_color normal
exit 1
end
echo "HERE!!!"
bind \cn '__savvy_run_completion__ "__savvy_run_completion__"'
echo
Expand All @@ -134,7 140,10 @@ echo
`

func (f *fish) SpawnRunbookRunner(ctx context.Context, runbook *client.Runbook) (*exec.Cmd, error) {
tmpDir := os.TempDir()
tmpDir, err := os.MkdirTemp("", "savvy-fish-*")
if err != nil {
return nil, err
}
fishVendorConfDir := filepath.Join(tmpDir, "fish", "vendor_conf.d")
if err := os.MkdirAll(fishVendorConfDir, 0755); err != nil {
return nil, err
Expand All @@ -151,9 160,9 @@ func (f *fish) SpawnRunbookRunner(ctx context.Context, runbook *client.Runbook)

dataDirs := os.Getenv("XDG_DATA_DIRS")
if dataDirs == "" {
dataDirs = fishVendorConfDir
dataDirs = tmpDir
} else {
dataDirs = strings.Join([]string{dataDirs, fishVendorConfDir}, ":")
dataDirs = strings.Join([]string{dataDirs, tmpDir}, ":")
}
cmd := exec.CommandContext(ctx, f.shellCmd)
cmd.Env = append(os.Environ(), "SAVVY_CONTEXT=run", fmt.Sprintf("XDG_DATA_DIRS=%s", dataDirs))
Expand Down

0 comments on commit 30c9bf1

Please sign in to comment.