- added handling for ~

- fixed crash when $VAR is null
This commit is contained in:
2026-02-10 19:30:31 -06:00
parent 540699a52b
commit b2d6050322
2 changed files with 25 additions and 3 deletions

View File

@@ -7,17 +7,22 @@ Going to try and make it mostly POSIX compliant.
- [x] environment variables - [x] environment variables
- [x] custom prompts - [x] custom prompts
- [ ] fix prompt to use PS1 environment variable
- [x] minimal current directory - [x] minimal current directory
- [ ] handle ~ - [x] handle ~
- [ ] dynamically allocate cwd in cd builtin command - [ ] dynamically allocate cwd in cd builtin command
- [ ] history
- [ ] cursor movement
- [ ] tab to autocomplete files and dirs
- [ ] all of posixsxssssss - [ ] all of posixsxssssss
- [ ] aliases - [ ] aliases
- [x] increase the SHLVL var - [x] increase the SHLVL var
- [x] update pwd - [x] update pwd
- [ ] quotes - [ ] quotes
- [ ] pipes | - [ ] pipes |
- [ ] vi mode
- [ ] redirections > < - [ ] redirections > <
- [ ] append >> - [ ] append >>
- [ ] heredoc - [ ] heredoc
- [ ] rcfile - [ ] rcfile
- [ ] rcfile in homedir - [ ] rcfile in config dir

View File

@@ -49,7 +49,24 @@ char *handle_vars(char *token){
token=&token[0]; token=&token[0];
if (token[0] == '$'){ if (token[0] == '$'){
token=&token[1]; 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; return token;