File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ export function cd(dir: string) {
8
8
console . log ( $ . brightBlue ( "$ %s" ) , `cd ${ dir } ` ) ;
9
9
}
10
10
try {
11
- if ( dir [ 0 ] !== path . sep ) {
11
+ if ( dir [ 0 ] === "~" ) {
12
+ dir = path . join ( homedir ( ) as string , dir . slice ( 1 ) ) ;
13
+ } else if ( dir [ 0 ] !== path . sep ) {
12
14
dir = new URL ( dir , path . toFileUrl ( cwd + path . sep ) ) . pathname ;
13
15
}
14
16
Deno . chdir ( dir ) ;
@@ -23,3 +25,15 @@ export function cd(dir: string) {
23
25
error ( err ) ;
24
26
}
25
27
}
28
+
29
+ function homedir ( ) : string | null {
30
+ switch ( Deno . build . os ) {
31
+ case "windows" :
32
+ return Deno . env . get ( "USERPROFILE" ) || null ;
33
+ case "linux" :
34
+ case "darwin" :
35
+ return Deno . env . get ( "HOME" ) || null ;
36
+ default :
37
+ throw Error ( "Failed to retrive home directory." ) ;
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments