Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding tab autocomplete feature #13

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions chell.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "chell.h"
#include <string.h>
#include <readline/readline.h>

int main()
{
Expand All @@ -16,12 +18,11 @@ int main()

while (1)
{
initPrompt();
//Command input
getline(&command, &size, stdin);
//Get prompt
char *promptString = initPrompt();

//Delete the newline
command[strlen(command)-1] = 0;
//Command input
command = readline(promptString);

//If not an empty command
if (strcmp(command, "") != 0)
Expand Down Expand Up @@ -81,7 +82,7 @@ struct executable *getFilesFromDirectories(char **dir, int numberOfDirectory)
return executables;
}

void initPrompt()
char *initPrompt()
{
//Get environment variables for the prompt
char *home = getenv("HOME");
Expand Down Expand Up @@ -120,7 +121,20 @@ void initPrompt()
else
prompt = '$';

printf("%s:%s%c ", user, pwd, prompt);
//printf("%s:%s%c ", user, pwd, prompt);
return createPromptString(user, pwd, prompt);
}

char *createPromptString(char *user, char *pwd, char prompt){
char *promptString = (char*)malloc(sizeof(char) * 100);
char p[5] = " "; p[0] = prompt;

strcpy(promptString, user);
strcat(promptString, ":");
strcat(promptString, pwd);
strcat(promptString, p);

return promptString;
}

int splitString(char *split[], char *string, char *delim)
Expand Down
3 changes: 2 additions & 1 deletion chell.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ int nExecutables = 0;
struct executable *getFilesFromDirectories(char **dir, int numberOfDirectory);


void initPrompt();
char *initPrompt();
char *createPromptString(char*, char*, char);

int splitString(char *split[], char *string, char *delim);
int splitCommand(char *argv[], char *command);
Expand Down