From 62eb04090a4c7fb03205d866a6296c42e0e60ef7 Mon Sep 17 00:00:00 2001 From: sawka Date: Mon, 9 Sep 2024 22:26:10 -0700 Subject: [PATCH] fix shell integration directories, add bash/zsh completion scripts --- cmd/wsh/cmd/wshcmd-getmeta.go | 2 +- cmd/wsh/cmd/wshcmd-setmeta.go | 2 +- cmd/wsh/cmd/wshcmd-view.go | 6 ++-- cmd/wsh/cmd/wshcmd-web.go | 49 +++++++++++++++++++++++++++++++++ pkg/shellexec/shellexec.go | 6 ++-- pkg/util/shellutil/shellutil.go | 4 +++ 6 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 cmd/wsh/cmd/wshcmd-web.go diff --git a/cmd/wsh/cmd/wshcmd-getmeta.go b/cmd/wsh/cmd/wshcmd-getmeta.go index d85cfef45..f30fabba4 100644 --- a/cmd/wsh/cmd/wshcmd-getmeta.go +++ b/cmd/wsh/cmd/wshcmd-getmeta.go @@ -12,7 +12,7 @@ import ( ) var getMetaCmd = &cobra.Command{ - Use: "getmeta", + Use: "getmeta {blockid|blocknum|this} [key]", Short: "get metadata for an entity", Args: cobra.RangeArgs(1, 2), Run: getMetaRun, diff --git a/cmd/wsh/cmd/wshcmd-setmeta.go b/cmd/wsh/cmd/wshcmd-setmeta.go index c68041b68..c400363dd 100644 --- a/cmd/wsh/cmd/wshcmd-setmeta.go +++ b/cmd/wsh/cmd/wshcmd-setmeta.go @@ -14,7 +14,7 @@ import ( ) var setMetaCmd = &cobra.Command{ - Use: "setmeta", + Use: "setmeta {blockid|blocknum|this} key=value ...", Short: "set metadata for an entity", Args: cobra.MinimumNArgs(2), Run: setMetaRun, diff --git a/cmd/wsh/cmd/wshcmd-view.go b/cmd/wsh/cmd/wshcmd-view.go index 0a14f0321..0aed5d482 100644 --- a/cmd/wsh/cmd/wshcmd-view.go +++ b/cmd/wsh/cmd/wshcmd-view.go @@ -17,7 +17,7 @@ import ( var viewMagnified bool var viewCmd = &cobra.Command{ - Use: "view", + Use: "view {file|directory|URL}", Short: "preview/edit a file or directory", Args: cobra.ExactArgs(1), Run: viewRun, @@ -25,8 +25,8 @@ var viewCmd = &cobra.Command{ } var editCmd = &cobra.Command{ - Use: "edit", - Short: "preview/edit a file or directory", + Use: "edit {file}", + Short: "edit a file", Args: cobra.ExactArgs(1), Run: viewRun, PreRunE: preRunSetupRpcClient, diff --git a/cmd/wsh/cmd/wshcmd-web.go b/cmd/wsh/cmd/wshcmd-web.go new file mode 100644 index 000000000..f5bbc990e --- /dev/null +++ b/cmd/wsh/cmd/wshcmd-web.go @@ -0,0 +1,49 @@ +// Copyright 2024, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/wavetermdev/waveterm/pkg/waveobj" + "github.com/wavetermdev/waveterm/pkg/wshrpc" + "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" +) + +var webCmd = &cobra.Command{ + Use: "web [open|get|set]", + Short: "web commands", + PersistentPreRunE: preRunSetupRpcClient, +} + +var webOpenCommand = &cobra.Command{ + Use: "open url", + Short: "open a url a web widget", + Args: cobra.ExactArgs(1), + RunE: webOpenRun, +} + +func init() { + webCmd.AddCommand(webOpenCommand) + rootCmd.AddCommand(webCmd) +} + +func webOpenRun(cmd *cobra.Command, args []string) error { + wshCmd := wshrpc.CommandCreateBlockData{ + BlockDef: &waveobj.BlockDef{ + Meta: map[string]any{ + waveobj.MetaKey_View: "web", + waveobj.MetaKey_Url: args[0], + }, + }, + Magnified: viewMagnified, + } + oref, err := wshclient.CreateBlockCommand(RpcClient, wshCmd, nil) + if err != nil { + return fmt.Errorf("creating block: %w", err) + } + WriteStdout("created block %s\n", oref) + return nil +} diff --git a/pkg/shellexec/shellexec.go b/pkg/shellexec/shellexec.go index 75a45d096..e5d483469 100644 --- a/pkg/shellexec/shellexec.go +++ b/pkg/shellexec/shellexec.go @@ -162,11 +162,11 @@ func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts Comm log.Printf("recognized as bash shell") // add --rcfile // cant set -l or -i with --rcfile - shellOpts = append(shellOpts, "--rcfile", fmt.Sprintf(`"%s"/.waveterm/bash-integration/.bashrc`, homeDir)) + shellOpts = append(shellOpts, "--rcfile", fmt.Sprintf(`"%s"/.waveterm/%s/.bashrc`, homeDir, shellutil.BashIntegrationDir)) } else if remote.IsPowershell(shellPath) { // powershell is weird about quoted path executables and requires an ampersand first shellPath = "& " + shellPath - shellOpts = append(shellOpts, "-NoExit", "-File", homeDir+"/.waveterm/pwsh-integration/wavepwsh.ps1") + shellOpts = append(shellOpts, "-NoExit", "-File", homeDir+fmt.Sprintf("/.waveterm/%s/wavepwsh.ps1", shellutil.PwshIntegrationDir)) } else { if cmdOpts.Login { shellOpts = append(shellOpts, "-l") @@ -227,7 +227,7 @@ func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts Comm } if isZshShell(shellPath) { - cmdCombined = fmt.Sprintf(`ZDOTDIR="%s/.waveterm/zsh-integration" %s`, homeDir, cmdCombined) + cmdCombined = fmt.Sprintf(`ZDOTDIR="%s/.waveterm/%s" %s`, homeDir, shellutil.ZshIntegrationDir, cmdCombined) } jwtToken, ok := cmdOpts.Env[wshutil.WaveJwtTokenVarName] diff --git a/pkg/util/shellutil/shellutil.go b/pkg/util/shellutil/shellutil.go index cc87d08aa..d7b15ab7a 100644 --- a/pkg/util/shellutil/shellutil.go +++ b/pkg/util/shellutil/shellutil.go @@ -51,6 +51,7 @@ const ( [ -f ~/.zshrc ] && source ~/.zshrc export PATH={{.WSHBINDIR}}:$PATH +source <(wsh completion zsh) ` ZshStartup_Zlogin = ` @@ -78,6 +79,9 @@ elif [ -f ~/.profile ]; then fi export PATH={{.WSHBINDIR}}:$PATH + +source <(wsh completion bash) + ` PwshStartup_wavepwsh = ` # no need to source regular profiles since we cannot