Skip to content

Commit

Permalink
Add cd command
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Dec 4, 2018
1 parent 6a7af28 commit 91be5c7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cmd/cd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
"github.com/twpayne/go-shell"
"github.com/twpayne/go-vfs"
)

var cdCommand = &cobra.Command{
Use: "cd",
Args: cobra.NoArgs,
Short: "Launch a shell in your source directory",
RunE: makeRunE(config.runCDCommand),
}

func init() {
rootCommand.AddCommand(cdCommand)
}

func (c *Config) runCDCommand(fs vfs.FS, cmd *cobra.Command, args []string) error {
if err := os.Chdir(c.SourceDir); err != nil {
return err
}
shell, err := shell.CurrentUserShell()
if err != nil {
return err
}
return c.exec([]string{shell})
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/spf13/viper v1.2.1
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.2.2 // indirect
github.com/twpayne/go-shell v0.0.1
github.com/twpayne/go-vfs v0.1.3
github.com/zalando/go-keyring v0.0.0-20180221093347-6d81c293b3fb
golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/twpayne/go-shell v0.0.1 h1:Ako3cUeuULhWadYk37jM3FlJ8lkSSW4INBjYj9K60Gw=
github.com/twpayne/go-shell v0.0.1/go.mod h1:QCjEvdZndTuPObd+11NYAI1UeNLSuGZVxJ+67Wl+IU4=
github.com/twpayne/go-vfs v0.1.3 h1:xyBrYwrvm3GfQ92iwJmr1F0yXI+4Pz8J50IwHfq79Bg=
github.com/twpayne/go-vfs v0.1.3/go.mod h1:OIXA6zWkcn7Jk46XT7ceYqBMeIkfzJ8WOBhGJM0W4y8=
github.com/zalando/go-keyring v0.0.0-20180221093347-6d81c293b3fb h1:tXbazu9ZlecQbyCczvA22mWj+lw/36Bdwxapk8v7e7s=
Expand Down

0 comments on commit 91be5c7

Please sign in to comment.