Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions cmd/wsh/cmd/wshcmd-rcfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
package cmd

import (
"path/filepath"

"github.com/spf13/cobra"
"github.com/wavetermdev/waveterm/pkg/util/shellutil"
"github.com/wavetermdev/waveterm/pkg/wavebase"
"github.com/wavetermdev/waveterm/pkg/wshutil"
)

func init() {
Expand All @@ -20,10 +17,7 @@ var rcfilesCmd = &cobra.Command{
Hidden: true,
Short: "Generate the rc files needed for various shells",
Run: func(cmd *cobra.Command, args []string) {
home := wavebase.GetHomeDir()
waveDir := filepath.Join(home, wavebase.RemoteWaveHomeDirName)
winBinDir := filepath.Join(waveDir, wavebase.RemoteWshBinDirName)
err := shellutil.InitRcFiles(waveDir, winBinDir)
err := wshutil.InstallRcFiles()
if err != nil {
WriteStderr(err.Error())
return
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/store/wshclientapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ class RpcApiType {
return client.wshRpcCall("remotegetinfo", null, opts);
}

// command "remoteinstallrcfiles" [call]
RemoteInstallRcFilesCommand(client: WshClient, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("remoteinstallrcfiles", null, opts);
}

// command "remotemkdir" [call]
RemoteMkdirCommand(client: WshClient, data: string, opts?: RpcOpts): Promise<void> {
return client.wshRpcCall("remotemkdir", data, opts);
Expand Down
13 changes: 0 additions & 13 deletions pkg/remote/connutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,6 @@ func CpWshToRemote(ctx context.Context, client *ssh.Client, clientOs string, cli
return nil
}

func InstallClientRcFiles(client *ssh.Client) error {
path := GetWshPath(client)
log.Printf("path to wsh searched is: %s", path)
session, err := client.NewSession()
if err != nil {
// this is a true error that should stop further progress
return err
}

_, err = session.Output(path + " rcfiles")
return err
}

func IsPowershell(shellPath string) bool {
// get the base path, and then check contains
shellBase := filepath.Base(shellPath)
Expand Down
2 changes: 1 addition & 1 deletion pkg/shellexec/shellexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts Comm
var cmdCombined string
log.Printf("using shell: %s", shellPath)

err = remote.InstallClientRcFiles(client)
err = wshclient.RemoteInstallRcFilesCommand(rpcClient, &wshrpc.RpcOpts{Route: connRoute, Timeout: 2000})
if err != nil {
log.Printf("error installing rc files: %v", err)
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions pkg/wshrpc/wshclient/wshclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ func RemoteGetInfoCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) (wshrpc.Remot
return resp, err
}

// command "remoteinstallrcfiles", wshserver.RemoteInstallRcFilesCommand
func RemoteInstallRcFilesCommand(w *wshutil.WshRpc, opts *wshrpc.RpcOpts) error {
_, err := sendRpcRequestCallHelper[any](w, "remoteinstallrcfiles", nil, opts)
return err
}

// command "remotemkdir", wshserver.RemoteMkdirCommand
func RemoteMkdirCommand(w *wshutil.WshRpc, data string, opts *wshrpc.RpcOpts) error {
_, err := sendRpcRequestCallHelper[any](w, "remotemkdir", data, opts)
Expand Down
4 changes: 4 additions & 0 deletions pkg/wshrpc/wshremote/wshremote.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,7 @@ func (*ServerImpl) RemoteFileDeleteCommand(ctx context.Context, path string) err
func (*ServerImpl) RemoteGetInfoCommand(ctx context.Context) (wshrpc.RemoteInfo, error) {
return wshutil.GetInfo(), nil
}

func (*ServerImpl) RemoteInstallRcFilesCommand(ctx context.Context) error {
return wshutil.InstallRcFiles()
}
2 changes: 2 additions & 0 deletions pkg/wshrpc/wshrpctypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
Command_SetVar = "setvar"
Command_RemoteMkdir = "remotemkdir"
Command_RemoteGetInfo = "remotegetinfo"
Command_RemoteInstallRcfiles = "remoteinstallrcfiles"

Command_ConnStatus = "connstatus"
Command_WslStatus = "wslstatus"
Expand Down Expand Up @@ -181,6 +182,7 @@ type WshRpcInterface interface {
RemoteMkdirCommand(ctx context.Context, path string) error
RemoteStreamCpuDataCommand(ctx context.Context) chan RespOrErrorUnion[TimeSeriesData]
RemoteGetInfoCommand(ctx context.Context) (RemoteInfo, error)
RemoteInstallRcFilesCommand(ctx context.Context) error

// emain
WebSelectorCommand(ctx context.Context, data CommandWebSelectorData) ([]string, error)
Expand Down
8 changes: 8 additions & 0 deletions pkg/wshutil/wshutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"net"
"os"
"os/signal"
"path/filepath"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -561,3 +562,10 @@ func GetInfo() wshrpc.RemoteInfo {
}

}

func InstallRcFiles() error {
home := wavebase.GetHomeDir()
waveDir := filepath.Join(home, wavebase.RemoteWaveHomeDirName)
winBinDir := filepath.Join(waveDir, wavebase.RemoteWshBinDirName)
return shellutil.InitRcFiles(waveDir, winBinDir)
}
Comment on lines +566 to +571
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for home directory.

While the centralization of path construction logic is good, the function should handle the case where GetHomeDir() returns an empty string.

 func InstallRcFiles() error {
 	home := wavebase.GetHomeDir()
+	if home == "" {
+		return fmt.Errorf("home directory not found")
+	}
 	waveDir := filepath.Join(home, wavebase.RemoteWaveHomeDirName)
 	winBinDir := filepath.Join(waveDir, wavebase.RemoteWshBinDirName)
 	return shellutil.InitRcFiles(waveDir, winBinDir)
 }

Committable suggestion skipped: line range outside the PR's diff.

Loading