forked from navinkumar-classic/NewAge_Terminal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
back.py
45 lines (36 loc) · 1.13 KB
/
back.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
import subprocess
import re
from Hash import *
def get_fcmd(command):
l = list(command.split())
if len(l) > 0: return l[0]
else: return ""
def find_alias(command):
for i in alias_arr:
bool_x = re.search(i, command)
if bool_x:
command = command.replace(i,alias_hash.get(i)[0])
break
return command
# Run the command and capture the output
def run_cmd(command):
command = find_alias(command)
func,bool_2 = hash_database.get(get_fcmd(command))
if bool_2:
return func(command)
else:
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# Check if the command was successful (return code 0)
if result.returncode == 0:
output = result.stdout
return output
else:
error = result.stderr
return error
def clean_cmd(command):
x = re.findall("\$.+", command)
return x[0][1:].strip()
def get_shrt_dir(dir):
dir_list = dir.split('\\')
#return dir_list[0] + "\\...\\" + dir_list[-1]
return dir_list[-1]