-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhistory-compact
More file actions
executable file
·26 lines (21 loc) · 876 Bytes
/
history-compact
File metadata and controls
executable file
·26 lines (21 loc) · 876 Bytes
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
#!/usr/bin/env python3
import sys
seen = {}
current_command = []
current_timestamp = None
for line in sys.stdin:
if line.startswith("#"):
if current_timestamp is not None: # Output the previous command
current_command_str = ''.join(current_command).strip()
if current_command_str and current_command_str not in seen:
seen[current_command_str] = True
sys.stdout.write(current_timestamp + '\n' + current_command_str + '\n')
current_timestamp = line.strip()
current_command = []
else:
current_command.append(line)
# Handle the last command
if current_timestamp is not None:
current_command_str = ''.join(current_command).strip()
if current_command_str and current_command_str not in seen:
sys.stdout.write(current_timestamp + '\n' + current_command_str + '\n')