aboutsummaryrefslogtreecommitdiff
path: root/cmd/myshell/main.go
diff options
context:
space:
mode:
authorjet2tlf <jet2tlf@gmail.com>2024-05-31 04:55:01 +0000
committerjet2tlf <jet2tlf@gmail.com>2024-05-31 04:55:01 +0000
commit7110baf5dd384ad92409e05eb627b534e9e35c16 (patch)
tree9d2e684d99c1d8d69066f1b95b52bfd887ac7cb2 /cmd/myshell/main.go
parent8f0373f4f7b68ddc85dbc493c0b98de91bb56995 (diff)
downloadshell-go-7110baf5dd384ad92409e05eb627b534e9e35c16.tar.gz
shell-go-7110baf5dd384ad92409e05eb627b534e9e35c16.zip
pass 12st stage
Diffstat (limited to 'cmd/myshell/main.go')
-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 {