FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Shell-Development-Project/main.cpp at mycode · Shell-Development-Project/Shell-Development-Project · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Shell-Development-Project
/
Shell-Development-Project
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Shell-Development-Project
/
main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
163 lines (141 loc) · 4.41 KB
Breadcrumbs
Shell-Development-Project
/
main.cpp
Copy path
File metadata and controls
executable file
·
163 lines (141 loc) · 4.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
input
*/
//
/-------------------------------------------------------------------------------------
/*
AUTHOR: Akash Agarwal
1405231007-Computer Science Department
IET LUCKNOW
LIFE MOTTO: while(!(suceed=try()))
*/
//
/--------------------------------------------------------------------------------------
//
Predefined #INCLUDES
#
include
<
iostream
>
#
include
<
vector
>
#
include
<
string
>
#
include
<
algorithm
>
#
include
<
stdio.h
>
#
include
<
string.h
>
#
include
<
math.h
>
#
include
<
stdlib.h
>
#
include
<
unistd.h
>
#
include
<
readline/readline.h
>
#
include
<
readline/history.h
>
#
include
<
boost/filesystem.hpp
>
#
include
<
boost/algorithm/string/replace.hpp
>
//
User Defined #INCLUDES
#
include
"
lexical.h
"
//
#include "termcolor.hpp"
using
namespace
std
;
/*
ANSI colour codes.
**Note that not all terminals support this; if colour sequences are not supported, garbage will show up.**
Example:
cout << "\033[1;31mbold red text\033[0m\n";
Here, \033 is the ESC character, ASCII 27. It is followed by [, then zero or more numbers separated by ;,
and finally the letter m. The numbers describe the colour and format to switch to from that point onwards.
The codes for foreground and background colours are:
____________________________________
foreground background
black 30 40
red 31 41
green 32 42
yellow 33 43
blue 34 44
magenta 35 45
cyan 36 46
white 37 47
_____________________________________
Additionally, we can use these:
_________________________________________________________________
reset 0 (everything back to normal)
bold/bright 1 (often a brighter shade of the same colour)
underline 4
inverse 7 (swap foreground and background colours)
bold/bright off 21
underline off 24
inverse off 27
__________________________________________________________________
See the table on Wikipedia for other, less widely supported codes.
*/
#
define
ANSI_COLOR_RED
"
\x1B
[1;31m
"
#
define
ANSI_COLOR_YELLOW
"
\x1B
[1;33m
"
#
define
ANSI_COLOR_BLUE
"
\x1B
[1;34m
"
#
define
ANSI_COLOR_RESET
"
\x1B
[1;0m
"
#
define
ANSI_COLOR_WHITE
"
\x1B
[37m
"
#
define
ANSI_COLOR_GREEN
"
\x1B
[1;32m
"
int
main
()
{
string pathtoHome, username, hostname;
username =
string
(
getenv
(
"
USER
"
));
//
If compiler is showing error: "basic_string::_M_construct null not valid"
//
that means Ubuntu isn't exporting the variable like it should,
//
put "export HOSTNAME" in "/etc/bash.bashrc" and the code works.
hostname =
string
(
getenv
(
"
HOSTNAME
"
));
//
it will export both the username and the hostname.
pathtoHome =
"
/home/
"
+ username;
chdir
(pathtoHome.
c_str
());
static
char
* line_read = (
char
*)
NULL
;
while
(
true
)
{
string prompt =
"
\n
"
+
username
//
+
//
ANSI_COLOR_RED
+
"
@
"
//
+
//
ANSI_COLOR_GREEN
+
hostname
//
+
//
ANSI_COLOR_YELLOW
+
"
:
"
//
+
//
ANSI_COLOR_BLUE
+
boost::algorithm::replace_all_copy
(
boost::filesystem::current_path
().
string
(), pathtoHome,
"
~
"
)
//
+
//
ANSI_COLOR_RESET
+
"
!>>
"
;
line_read =
readline
(prompt.
c_str
());
if
(! line_read ||
strcmp
(line_read,
"
exit
"
) ==
0
)
{
cout << endl;
break
;
}
/*
If the line has any text in it, save it on the history.
*/
if
(line_read && *line_read)
add_history
(line_read);
try
{
string
cmd
(line_read);
cmdSyntaxAnalysis
(cmd);
}
catch
(
const
std::exception& e)
{
cout << e.
what
() <<
"
\n
"
;
}
}
return
0
;
}
//
/* A static variable for holding the line. */
//
static char *line_read = (char *)NULL;
//
/* Read a string, and return a pointer to it. Returns NULL on EOF. */
//
char *
//
rl_gets ()
//
{
//
/* If the buffer has already been allocated, return the memory
//
to the free pool. */
//
if (line_read)
//
{
//
free (line_read);
//
line_read = (char *)NULL;
//
}
//
/* Get a line from the user. */
//
line_read = readline ("");
//
/* If the line has any text in it, save it on the history. */
//
if (line_read && *line_read)
//
add_history (line_read);
//
return (line_read);
//
}
Back
|
FazBrowse Home
|
New Git URL