aboutsummaryrefslogtreecommitdiff
path: root/cmd/myshell
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/myshell')
-rw-r--r--cmd/myshell/main.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/cmd/myshell/main.go b/cmd/myshell/main.go
index 08db887..40de651 100644
--- a/cmd/myshell/main.go
+++ b/cmd/myshell/main.go
@@ -50,13 +50,23 @@ func main() {
}
func Cd(dir string) {
+ if len(dir) < 1 {
+ fmt.Println("path expected")
+ return
+ }
+
p := path.Clean(dir)
- if !path.IsAbs(p) {
+ if !path.IsAbs(p) && dir != "~" {
dir, _ := os.Getwd()
p = path.Join(dir, p)
}
+ if dir == "~" {
+ home, _ := os.UserHomeDir()
+ p = home + dir
+ }
+
err := os.Chdir(p)
if err != nil {