fix shell integration directories, add bash/zsh completion scripts

This commit is contained in:
sawka 2024-09-09 22:26:10 -07:00
parent 16d01b43eb
commit 62eb04090a
6 changed files with 61 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import (
) )
var getMetaCmd = &cobra.Command{ var getMetaCmd = &cobra.Command{
Use: "getmeta", Use: "getmeta {blockid|blocknum|this} [key]",
Short: "get metadata for an entity", Short: "get metadata for an entity",
Args: cobra.RangeArgs(1, 2), Args: cobra.RangeArgs(1, 2),
Run: getMetaRun, Run: getMetaRun,

View File

@ -14,7 +14,7 @@ import (
) )
var setMetaCmd = &cobra.Command{ var setMetaCmd = &cobra.Command{
Use: "setmeta", Use: "setmeta {blockid|blocknum|this} key=value ...",
Short: "set metadata for an entity", Short: "set metadata for an entity",
Args: cobra.MinimumNArgs(2), Args: cobra.MinimumNArgs(2),
Run: setMetaRun, Run: setMetaRun,

View File

@ -17,7 +17,7 @@ import (
var viewMagnified bool var viewMagnified bool
var viewCmd = &cobra.Command{ var viewCmd = &cobra.Command{
Use: "view", Use: "view {file|directory|URL}",
Short: "preview/edit a file or directory", Short: "preview/edit a file or directory",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
Run: viewRun, Run: viewRun,
@ -25,8 +25,8 @@ var viewCmd = &cobra.Command{
} }
var editCmd = &cobra.Command{ var editCmd = &cobra.Command{
Use: "edit", Use: "edit {file}",
Short: "preview/edit a file or directory", Short: "edit a file",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
Run: viewRun, Run: viewRun,
PreRunE: preRunSetupRpcClient, PreRunE: preRunSetupRpcClient,

49
cmd/wsh/cmd/wshcmd-web.go Normal file
View File

@ -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
}

View File

@ -162,11 +162,11 @@ func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts Comm
log.Printf("recognized as bash shell") log.Printf("recognized as bash shell")
// add --rcfile // add --rcfile
// cant set -l or -i with --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) { } else if remote.IsPowershell(shellPath) {
// powershell is weird about quoted path executables and requires an ampersand first // powershell is weird about quoted path executables and requires an ampersand first
shellPath = "& " + shellPath 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 { } else {
if cmdOpts.Login { if cmdOpts.Login {
shellOpts = append(shellOpts, "-l") shellOpts = append(shellOpts, "-l")
@ -227,7 +227,7 @@ func StartRemoteShellProc(termSize waveobj.TermSize, cmdStr string, cmdOpts Comm
} }
if isZshShell(shellPath) { 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] jwtToken, ok := cmdOpts.Env[wshutil.WaveJwtTokenVarName]

View File

@ -51,6 +51,7 @@ const (
[ -f ~/.zshrc ] && source ~/.zshrc [ -f ~/.zshrc ] && source ~/.zshrc
export PATH={{.WSHBINDIR}}:$PATH export PATH={{.WSHBINDIR}}:$PATH
source <(wsh completion zsh)
` `
ZshStartup_Zlogin = ` ZshStartup_Zlogin = `
@ -78,6 +79,9 @@ elif [ -f ~/.profile ]; then
fi fi
export PATH={{.WSHBINDIR}}:$PATH export PATH={{.WSHBINDIR}}:$PATH
source <(wsh completion bash)
` `
PwshStartup_wavepwsh = ` PwshStartup_wavepwsh = `
# no need to source regular profiles since we cannot # no need to source regular profiles since we cannot