aboutsummaryrefslogtreecommitdiffstats
path: root/src/lush.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-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");
}