-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathli.py
129 lines (104 loc) · 4.92 KB
/
li.py
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
#!/usr/bin/env python3
# MIT License
#
# Copyright (c) 2021 Ferhat Geçdoğan All Rights Reserved.
# Distributed under the terms of the MIT License.
#
#
# Li[dot]py : Python3 implementation of Scrift's list-directory command.
#
# github.com/ferhatgec/scrift
# ===========================
# github.com/ferhatgec/lirs
#
from os import path, listdir, getcwd
from pathlib import Path
from re import search
class Lipy:
def __init__(self):
self.directory = getcwd()
self.file = ''
self.everything = [] # tuple(str, str, int)
# ^^^ ^^^ ^^^
# name ext color
def between(self, data: str, substring: str, substring2: str) -> str:
return search(substring + '(.*)' + substring2, data).group(1)
# Parser for Li[dot]py
#
# Syntax:
#
# > '[Kalem]: ' < > "kalem" < > {95} <
# ^^^^^^^^^ ^^^^^^^^^^^ ^^^^^
# > 'name' < > "extension" < > {ansi_color} <
#
def get(self, extension: str) -> tuple:
extension = extension[1:]
for data in self.everything:
if extension == data[1]:
return (data[0], data[2])
return ('[File]: ', 34)
def parse(self, data: str):
color = int(self.between(data, '\>\{', '\}\<'))
if color == 0:
color = 34
name = self.between(data, '\>\'', '\'<')
extension = self.between(data, '\>\"', '\"<')
self.everything.append((name, extension, color))
def read_data(self):
if path.exists(str(Path.home()) + '/' + '.lirs_data'):
file_data = open(str(Path.home()) + '/' + '.lirs_data')
for line in file_data.readlines():
self.parse(line)
else:
open(str(Path.home()) + '/' + '.lirs_data', "x")
self.read_data()
def printf(self, color, data):
print(color, data, '\033[1;97m', self.file, sep='', end='\n')
def match(self, arg):
if path.isdir(arg):
self.printf('\033[1;94m', '[Direc]: ')
return
arg = path.splitext(arg)[1]
# Built-in extensions.
if arg == '.scrift_log': self.printf('\033[1;33m', 'FeLog*: ')
elif arg == '.scrift_ascii': self.printf('\033[1;33m', 'Ascii Art*: ')
elif arg == '.scrift_settings': self.printf('\033[1;33m','Settings*: ')
elif arg == '.scrift_history': self.printf('\033[1;33m', 'History*: ')
elif arg == '.scr': self.printf('\033[1;32m', '[Scrift]: ')
elif arg == '.cpp': self.printf('\033[1;36m', '[C++]: ')
elif arg == '.hpp': self.printf('\033[1;36m', '[C++]: ')
elif arg == '.cxx': self.printf('\033[1;36m', '[C++]: ')
elif arg == '.hxx': self.printf('\033[1;36m', '[C++]: ')
elif arg == '.cc': self.printf('\033[1;36m', '[C++]: ')
elif arg == '.hh': self.printf('\033[1;36m', '[C++]: ')
elif arg == '.c': self.printf('\033[1;34m', '[C]: ')
elif arg == '.h': self.printf('\033[1;34m', '[C]: ')
elif arg == '.sh': self.printf('\033[1;32m', '[Bash]: ')
elif arg == '.bash': self.printf('\033[1;32m', '[Bash]: ')
elif arg == '.py': self.printf('\033[1;34m', '[Python]: ')
elif arg == '.pyc': self.printf('\033[1;34m', '[Python]: ')
elif arg == '.fls': self.printf('\033[1;33m', '[FlaScript]: ')
elif arg == '.flsh': self.printf('\033[1;33m', '[FlaScript]: ')
elif arg == '.md': self.printf('\033[1;33m', '[Markdown]: ')
elif arg == '.freebr': self.printf('\033[1;35m', '[FreeBr]: ')
elif arg == '.png': self.printf('\033[1;34m', '[Png]: ')
elif arg == '.jpg': self.printf('\033[1;34m', '[Jpg]: ')
elif arg == '.jpeg': self.printf('\033[1;34m', '[Jpg]: ')
elif arg == '.gif': self.printf('\033[1;34m', '[Gif]: ')
elif arg == '.htm': self.printf('\033[1;35m', '[Html]: ')
elif arg == '.html': self.printf('\033[1;35m', '[Html]: ')
elif arg == '.rs': self.printf('\033[1;33m', '[Rust]: ')
elif arg == '.rslib': self.printf('\033[1;33m', '[Rust]: ')
elif arg == '.lua': self.printf('\033[1;0m', '[Lua]: ')
elif arg == '.inclink': self.printf('\033[1;35m', '[incLink]: ')
else:
get = self.get(arg)
self.printf('\033[1;{}m'.format(get[1]), get[0])
def match_content(self):
dirs = listdir(getcwd())
self.read_data()
for data in dirs:
self.file = data
self.match(data)
init = Lipy()
init.match_content()