-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
- Add a new `sesh preview` command - Add configuration support for the preview command
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ls | ||
|
||
import ( | ||
"github.com/joshmedeski/sesh/model" | ||
"github.com/joshmedeski/sesh/shell" | ||
) | ||
|
||
type Ls interface { | ||
ListDirectory(name string) (string, error) | ||
} | ||
|
||
type RealLs struct { | ||
config model.Config | ||
shell shell.Shell | ||
} | ||
|
||
func NewLs(config model.Config, shell shell.Shell) Ls { | ||
return &RealLs{config, shell} | ||
} | ||
|
||
func (g *RealLs) ListDirectory(path string) (string, error) { | ||
command := g.config.DefaultSessionConfig.PreviewCommand | ||
if command == "" { | ||
command = "ls {}" | ||
} | ||
|
||
cmdParts, err := g.shell.PrepareCmd(command, map[string]string{"{}": path}) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
cmdOutput, err := g.shell.Cmd(cmdParts[0], cmdParts[1:]...) | ||
if err != nil { | ||
return "", err | ||
} | ||
return cmdOutput, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package previewer | ||
|
||
import ( | ||
"github.com/joshmedeski/sesh/lister" | ||
"github.com/joshmedeski/sesh/shell" | ||
) | ||
|
||
type ConfigPreviewStrategy struct { | ||
lister lister.Lister | ||
shell shell.Shell | ||
} | ||
|
||
func NewConfigStrategy(lister lister.Lister, shell shell.Shell) *ConfigPreviewStrategy { | ||
return &ConfigPreviewStrategy{lister: lister, shell: shell} | ||
} | ||
|
||
func (s *ConfigPreviewStrategy) Execute(name string) (string, error) { | ||
session, configExists := s.lister.FindConfigSession(name) | ||
if !configExists { | ||
return "", nil | ||
} | ||
|
||
if session.PreviewCommand == "" { | ||
return "", nil | ||
} | ||
|
||
replacements := map[string]string{ | ||
"{}": session.Path, | ||
} | ||
cmdParts, err := s.shell.PrepareCmd(session.PreviewCommand, replacements) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
cmdOutput, err := s.shell.Cmd(cmdParts[0], cmdParts[1:]...) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return cmdOutput, nil | ||
} |