diff options
| author | 2024-09-11 12:05:42 -0400 | |
|---|---|---|
| committer | 2024-09-11 12:05:42 -0400 | |
| commit | 3165d96f8056548cf582e89d5a9c019c99c7fdd4 (patch) | |
| tree | e8ef5fcb063626821865f4bb5e47b7a54d11b21e | |
| parent | added date format specifier for prompt (diff) | |
added OLDPWD environment var and cd - to go to OLDPWD
Diffstat (limited to '')
| -rw-r--r-- | src/lush.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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"); } |
