forked from Spencer/math_shell
Compare commits
1 Commits
a458e4f55c
...
push-lnwls
| Author | SHA1 | Date | |
|---|---|---|---|
| 76cb69f0a5 |
@@ -163,6 +163,7 @@ fn cdFn(shell_state: *ShellState, command: [][]const u8, allocator: Allocator) !
|
|||||||
const old_pwd = env_map.get("OLDPWD");
|
const old_pwd = env_map.get("OLDPWD");
|
||||||
const home = env_map.get("HOME");
|
const home = env_map.get("HOME");
|
||||||
defer allocator.free(pwd);
|
defer allocator.free(pwd);
|
||||||
|
var buf: [fs.max_path_bytes]u8 = undefined;
|
||||||
var err: ?anyerror = null;
|
var err: ?anyerror = null;
|
||||||
|
|
||||||
var target: ?[]const u8 = null;
|
var target: ?[]const u8 = null;
|
||||||
@@ -170,6 +171,12 @@ fn cdFn(shell_state: *ShellState, command: [][]const u8, allocator: Allocator) !
|
|||||||
if (home) |h| {
|
if (home) |h| {
|
||||||
target = h;
|
target = h;
|
||||||
}
|
}
|
||||||
|
} else if (command[1][0] == '~') {
|
||||||
|
if (home) |h| {
|
||||||
|
const numReplacements = mem.replace(u8, command[1], "~", h, &buf);
|
||||||
|
const len = command[1].len - numReplacements + (numReplacements * h.len);
|
||||||
|
target = buf[0..len];
|
||||||
|
}
|
||||||
} else if (eql(u8, command[1], "-")) {
|
} else if (eql(u8, command[1], "-")) {
|
||||||
if (old_pwd) |old| {
|
if (old_pwd) |old| {
|
||||||
target = old;
|
target = old;
|
||||||
@@ -178,7 +185,6 @@ fn cdFn(shell_state: *ShellState, command: [][]const u8, allocator: Allocator) !
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var buf: [fs.max_path_bytes]u8 = undefined;
|
|
||||||
target = cwd.realpath(command[1], &buf) catch |e| blk: {
|
target = cwd.realpath(command[1], &buf) catch |e| blk: {
|
||||||
err = e;
|
err = e;
|
||||||
break :blk null;
|
break :blk null;
|
||||||
|
|||||||
Reference in New Issue
Block a user