From 3165d96f8056548cf582e89d5a9c019c99c7fdd4 Mon Sep 17 00:00:00 2001 From: BanceDev Date: Wed, 11 Sep 2024 12:05:42 -0400 Subject: added OLDPWD environment var and cd - to go to OLDPWD --- src/lush.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src') 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"); } -- cgit v1.2.3-59-g8ed1b