forked from JaiMaaSheeravali/Roosh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request JaiMaaSheeravali#13 from JaiMaaSheeravali/input-fix
Input fixed and builtin arguments
- Loading branch information
Showing
5 changed files
with
87 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#pragma once | ||
#include <string> | ||
|
||
int roosh_cd(char **args); | ||
int roosh_history(char **args); | ||
int roosh_exit(char **args); | ||
int roosh_rsh(char **args); | ||
int roosh_cd(char **args, int num_args); | ||
int roosh_history(char **args, int num_args); | ||
int roosh_exit(char **args, int num_args); | ||
int roosh_rsh(char **args, int num_args); | ||
|
||
void push_command(std::string cmd); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#define RESET "\033[0m" | ||
#define BLACK "\033[30m" /* Black */ | ||
#define RED "\033[31m" /* Red */ | ||
#define GREEN "\033[32m" /* Green */ | ||
#define YELLOW "\033[33m" /* Yellow */ | ||
#define BLUE "\033[34m" /* Blue */ | ||
#define MAGENTA "\033[35m" /* Magenta */ | ||
#define CYAN "\033[36m" /* Cyan */ | ||
#define WHITE "\033[37m" /* White */ | ||
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ | ||
#define BOLDRED "\033[1m\033[31m" /* Bold Red */ | ||
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ | ||
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ | ||
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ | ||
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ | ||
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ | ||
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,67 @@ | ||
#include <unistd.h> | ||
#include <limits.h> | ||
#include <pwd.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <iostream> | ||
|
||
#include <../include/color.hpp> | ||
|
||
using namespace std; | ||
|
||
void print_git_branch(); | ||
|
||
void print_input_format() | ||
{ | ||
cout << flush; | ||
|
||
char hostname[50]; | ||
struct passwd *p = getpwuid(getuid()); | ||
|
||
// Get the host name and user name of current user | ||
if (gethostname(hostname, sizeof(hostname)) == 0 && p) | ||
{ | ||
printf("\033[;34m%s@", p->pw_name); | ||
printf("%s\033[0m:", hostname); | ||
cout << BLUE << p->pw_name << "@"; | ||
cout << hostname << RESET; | ||
} | ||
|
||
// Print the current working directory of user | ||
char cwd[100]; | ||
|
||
cout << GREEN; | ||
if (getcwd(cwd, sizeof(cwd)) != NULL) | ||
{ | ||
printf("\033[;32m%s\033[0m", cwd); | ||
} | ||
cout << cwd; | ||
else | ||
{ | ||
printf("\033[;32m.\033[0m"); | ||
} | ||
cout << "."; | ||
cout << RESET; | ||
|
||
// Get git branch if current directory is a git directory | ||
print_git_branch(); | ||
printf("₹ "); | ||
cout << "₹ " << flush; | ||
} | ||
|
||
void print_git_branch() | ||
{ | ||
FILE *fp; | ||
char path[400]; | ||
char branch_name[400]; | ||
|
||
// Get current branch and save its name in a file. | ||
fp = popen("git branch --show-current 2>/dev/null", "r"); | ||
|
||
if (fp == NULL) | ||
if (fp == NULL){ | ||
pclose(fp); | ||
return; | ||
} | ||
|
||
// Read branch name and print current branch name | ||
fgets(path, 200, fp); | ||
path[strcspn(path, "\n")] = 0; | ||
fgets(branch_name, 200, fp); | ||
branch_name[strcspn(branch_name, "\n")] = 0; | ||
|
||
// Should check status if any error occurs | ||
pclose(fp); | ||
|
||
if (path && strcmp(path, "") == 0) | ||
if (branch_name && strcmp(branch_name, "") == 0) | ||
return; | ||
|
||
// print current branch name in red enclosed in round braces | ||
printf(" \033[31m(%s)\033[0m", path); | ||
|
||
// Should check status if any error occurs | ||
pclose(fp); | ||
cout << RED << " (" << branch_name << ")" << RESET; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters