From b2d605032286076f46beec73cc37d4a20ca06a18 Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Tue, 10 Feb 2026 19:30:31 -0600 Subject: [PATCH] - added handling for ~ - fixed crash when $VAR is null --- README.md | 9 +++++++-- src/lsh_main_func.c | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b1f243f..69f62db 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,22 @@ Going to try and make it mostly POSIX compliant. - [x] environment variables - [x] custom prompts +- [ ] fix prompt to use PS1 environment variable - [x] minimal current directory -- [ ] handle ~ +- [x] handle ~ - [ ] dynamically allocate cwd in cd builtin command +- [ ] history +- [ ] cursor movement +- [ ] tab to autocomplete files and dirs - [ ] all of posixsxssssss - [ ] aliases - [x] increase the SHLVL var - [x] update pwd - [ ] quotes - [ ] pipes | + - [ ] vi mode - [ ] redirections > < - [ ] append >> - [ ] heredoc - [ ] rcfile - - [ ] rcfile in homedir + - [ ] rcfile in config dir diff --git a/src/lsh_main_func.c b/src/lsh_main_func.c index c144238..6935cfb 100644 --- a/src/lsh_main_func.c +++ b/src/lsh_main_func.c @@ -49,7 +49,24 @@ char *handle_vars(char *token){ token=&token[0]; if (token[0] == '$'){ token=&token[1]; - token=getenv(token); + if(getenv(token)){ + token=getenv(token); + } else { + token=""; + } + } + if (token[0] == '~'){ + token=&token[1]; + char *orig = (char*)malloc(sizeof(char) * ( strlen(token) + strlen(getenv("HOME") + 1))); + strcpy(orig,token); + + //do not use strcpy(token,getenv("home")) + //it does weird doubleing memeory thing i dont understand + token=getenv("HOME"); + + strcat(token,orig); + printf("TOK: %s\n\n",token); + free(orig); } return token;