aboutsummaryrefslogtreecommitdiffstats
path: root/src/lush.c
diff options
context:
space:
mode:
authorGravatar BanceDev 2024-09-11 12:05:42 -0400
committerGravatar BanceDev 2024-09-11 12:05:42 -0400
commit3165d96f8056548cf582e89d5a9c019c99c7fdd4 (patch)
treee8ef5fcb063626821865f4bb5e47b7a54d11b21e /src/lush.c
parentadded date format specifier for prompt (diff)
added OLDPWD environment var and cd - to go to OLDPWD
Diffstat (limited to 'src/lush.c')
-rw-r--r--src/lush.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/lush.c b/src/lush.c
index eb3423a..26ad250 100644
--- a/src/lush.c
+++ b/src/lush.c
@@ -83,17 +83,26 @@ int lush_cd(lua_State *L, char ***args) {
char path[PATH_MAX];
char extended_path[PATH_MAX];
char *tilda = strchr(args[0][1], '~');
- if (tilda) {
+ // first check if they want to go to old dir
+ if (strcmp("-", args[0][1]) == 0) {
+ strcpy(path, getenv("OLDPWD"));
+ } else if (tilda) {
strcpy(path, pw->pw_dir);
strcat(path, tilda + 1);
} else {
strcpy(path, args[0][1]);
}
+
char *exp_path = realpath(path, extended_path);
if (!exp_path) {
perror("realpath");
return 1;
}
+
+ char *cwd = getcwd(NULL, 0);
+ setenv("OLDPWD", cwd, 1);
+ free(cwd);
+
if (chdir(exp_path) != 0) {
perror("lush: cd");
}