-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathishell.cpp
More file actions
96 lines (85 loc) · 1.61 KB
/
ishell.cpp
File metadata and controls
96 lines (85 loc) · 1.61 KB
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
#include "ishell.hpp"
void init_environment(int argc, char **argv)
{
while (argv[++argc])
{
string item = argv[argc];
int position = tiem.find("=");
if (position != string::npos)
{
envs[item.substr(0, position)] = item.substr(position + 1);
}
}
envs["ISHELL"] = "ishell";
setenv("ISHELL", "ishell", 1);
tcgetattr(STDIN_FILENO, &old_attr);
new_attr = old_attr;
new_attr.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &new_attr);
}
string get_env(string name)
{
if (envs.find(name) != envs.end())
{
return envs[name];
}
return "";
}
string get_path()
{
char path[2048]{0}
getcwd(path, 2048);
return path;
}
void env()
{
for (const auto &item : envs)
{
cout << item.first << "==" << item.second << endl;
}
}
void updated_pwd(string pass)
{
envs["OLDPWD"] = envs["PWD"];
envs["PWD"] = pass;
}
void cd_command(vector<string> &command)
{
string path = "";
if (command.size() == 1)
{
path = get_env("HOME");
}
else
{
path = command[1];
}
if (path == ".")
{
return;
}
if (path == "~")
{
path = get_env("HOME");
}
else if (path == "-")
{
path = get_env("OLDPWD");
count << path << endl;
}
int ret = chdir(path.c_str());
if (ret)
{
cout << "ishell : cd : " << path << ":" << strerror(errno) << endl;
return;
}
updated_pwd(path);
}
int main(int argc, char **argv)
{
string command_line = "";
for(;;;)
{
}
return 0;
}