-
Notifications
You must be signed in to change notification settings - Fork 0
/
substitute.py
32 lines (27 loc) · 909 Bytes
/
substitute.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
import sys
import os
import utils
def replace():
expected_last_cmd = sys.argv[1]
if not os.path.exists(utils.CACHE_PATH):
return
with open(utils.CACHE_PATH, "r") as f:
lines = [s.rstrip() for s in f.readlines()]
actual_last_cmd = lines[0][3:]
lines = lines[1:]
args = []
for arg in sys.argv[2:]:
try:
i = int(arg)
assert 0 <= i - 1 < len(lines), f"No file numbered {i}"
assert (
expected_last_cmd == actual_last_cmd
), f"Expected last command to be {expected_last_cmd} but was {actual_last_cmd}"
args.append(lines[i - 1])
except ValueError:
if arg.startswith("\\"):
arg = arg[1:]
args.append(arg)
print(" ".join(args))
if __name__ == "__main__":
replace()