forked from ExtReMLapin/gterm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
128 lines (101 loc) · 3.63 KB
/
Copy pathmain.lua
File metadata and controls
128 lines (101 loc) · 3.63 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
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
local table = table
GTerm = {}
GTerm.Path = "";
local function pastfolder() -- from ./garrysmod/lua/ to ./garrysmod/
local tblspl = string.Explode("/", GTerm.Path)
table.remove(tblspl)
table.remove(tblspl)
GTerm.Path = table.concat(tblspl, "/") .. "/" or ""
return
end
local function pathsanitise(text) -- remove last /
if string.sub( text, -1 ) == "/" then
return string.sub( text, 1, -2 )
end
return text
end
local function writeSpaces( num )
MsgC( Color(255,255,255), string.rep( " ", num ) )
end
local function pathfixmultipleslash() -- i can't identify my error, so i'm using this fix to remove "//" from path
GTerm.Path = string.gsub(GTerm.Path, "//", "/")
end
if system.IsLinux() then -- checking if we can write into folders
GTerm.CanWrite = file.Exists( "garrysmod/lua/bin/gmsv_fileio_linux.dll", "BASE_PATH" )
else
GTerm.CanWrite = file.Exists( "garrysmod/lua/bin/gmsv_fileio_win32.dll", "BASE_PATH" )
end
if GTerm.CanWrite then require("fileio") end
function GTerm.pwd() -- print path
pathfixmultipleslash()
MsgC(Color(50,250,50), "./" .. GTerm.Path .. "\n")
end
local function fuckalert(message)
MsgC(Color(255,0,0), "/!\\ ");
MsgC(Color(255,215,0), message);
MsgC(Color(255,0,0), " /!\\ \n");
end
function GTerm.mkdir(ply, cmd, args) -- make a new directory
pathfixmultipleslash()
if not GTerm.CanWrite then fuckalert("module fileio is missing") return end
if not args[1] then return end
if file.Exists(GTerm.Path .. args[1], "BASE_PATH") or file.IsDir(GTerm.Path .. args[1], "BASE_PATH") then return end
---fileio.MakeDirectory() -- later
end
function GTerm.ls() -- print files infos and directories
pathfixmultipleslash()
local maxsize = 0;
local maxsize2 = 0;
local tbl1, tbl2 = file.Find(GTerm.Path .. "*", "BASE_PATH")
for k, v in pairs(tbl2) do -- folders
MsgC(Color(50,250,50), string.format("./%s/\n", v))
end
for k, v in pairs(tbl1) do -- files
if #v > maxsize then
maxsize = #v
end
end
for k, v in pairs(tbl1) do -- files
if #tostring(file.Size(GTerm.Path .. v, "BASE_PATH")) > maxsize2 then
maxsize2 = #tostring(file.Size(GTerm.Path .. v, "BASE_PATH"))
end
end
for k, v in pairs(tbl1) do
local strlen = #v
local strlen2 =#tostring(file.Size(GTerm.Path .. v, "BASE_PATH"))
MsgC(Color(150,150,255), v);
writeSpaces( maxsize - strlen )
MsgC(Color(255,0,0), " | Size -> ");
MsgC(Color(150,150,255), file.Size(GTerm.Path .. v, "BASE_PATH"));
writeSpaces( maxsize2 - strlen2 )
MsgC(Color(255,0,0), " | Last time edited -> ");
MsgC(Color(150,150,255), os.date( "%d.%m.%y", file.Time(GTerm.Path .. v, "BASE_PATH")) .. "\n");
end
end
function GTerm.cd(ply, cmd, args) -- fall back !
pathfixmultipleslash()
if not args or #args == 0 then return end
text = args[1]
text = pathsanitise(text)
if #args == 1 and text != "" then
if text[1] == "." and GTerm.Path == "" then return end
if text == ".." then
pastfolder()
return
end
if (file.IsDir(GTerm.Path .. text .. "/", "BASE_PATH")) then
GTerm.Path = GTerm.Path .. text .. "/"
end
if string.Left(text, 3) == "../" and #args[1] > 3 then
pastfolder()
if (file.IsDir(GTerm.Path ..string.Right(text, #args[1] - 3) .. "/", "BASE_PATH")) then
GTerm.Path = GTerm.Path .. string.Right(text, #args[1] - 3) .. "/"
end
--GTerm.Path = GTerm.Path .. "/"
end
end
end
concommand.Add("pwd", GTerm.pwd, file.Find("*", "BASE_PATH")[1], "print current folder")
concommand.Add("ls", GTerm.ls, {"no args"}, "print files and folders in current folder")
concommand.Add("cd", GTerm.cd, file.Find("*", "BASE_PATH")[2], "go in another folder")
concommand.Add("mkdir", GTerm.mkdir)