Skip to content

Commit 47aedd5

Browse files
committed
Added login and hostname in prompt
1 parent 46cde67 commit 47aedd5

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/rshell.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ int main()
1515
{
1616
while(true)
1717
{
18+
if(NULL == getlogin())//Display login user
19+
{
20+
perror("getlogin");
21+
}
22+
else
23+
{
24+
cout << getlogin();
25+
}
26+
char host_name[64] ={0};
27+
if(-1 == gethostname(host_name,64))//Display host name
28+
{
29+
perror("hostname");
30+
}
31+
else
32+
{
33+
cout << "@" << host_name;
34+
}
1835
string commands;//Receive command line
1936
cout << "$";
2037
getline(cin,commands);

0 commit comments

Comments
 (0)