-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls_notes.py
More file actions
executable file
·54 lines (45 loc) · 1.2 KB
/
ls_notes.py
File metadata and controls
executable file
·54 lines (45 loc) · 1.2 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
#!/usr/bin/env python3
"""
WARNING: hack/trick behaviour depends on link name pointing to this script.
nls -> this_script
jls -> this_script
"""
import glob
import os
import re
import sys
HOME = os.getenv("HOME")
NOTES = os.path.join(HOME, "notes")
padding = " " * 3
def parse_line(line):
line = line.rstrip()
line = line.lstrip(" ")
while "**" in line:
line = line.replace("**", padding+"*")
line = line.replace("* ", padding + "* ")
line = line.replace("\t", padding)
line = padding + line
return(line)
def print_stuff(files):
for f in files:
print("%s:" % f)
fin = open(f, 'r')
for x in fin:
x = x.strip(" \n")
x = parse_line(x)
print(x)
print()
print("Index:")
for f in files:
print(padding + f)
if __name__ == '__main__':
script_name = os.path.basename(sys.argv[0])
if script_name == 'jls':
files = glob.glob(os.path.join(NOTES, "journal_*"))
elif script_name == 'nls':
files = glob.glob(os.path.join(NOTES, "note_*"))
else:
print("Link to this script as jls or nls.")
print(script_name)
files.sort(reverse=False)
print_stuff(files)