Permalink
Browse files

cwd-history: store paths chronologically with no duplicates

That's very close to what you get in zsh with `setopt HIST_IGNORE_DUPS`.

Coincidence? I think not!
  • Loading branch information...
dmerejkowsky committed May 30, 2017
1 parent d0a7db1 commit 0d5780c87dab3093266357663736d23296ca8b62
Showing with 6 additions and 4 deletions.
  1. +6 −4 bin/cwd-history
View
@@ -24,15 +24,17 @@ def read_db():
def write_db(paths):
db_path = get_db_path()
with open(db_path, "w") as fp:
fp.writelines(sorted(x + "\n" for x in paths))
fp.writelines(x + "\n" for x in paths)
def add_to_db(path):
# Make sure the latest past is always at the *end* of the list:
paths = read_db()
if path not in paths:
paths.append(path)
write_db(paths)
if path in paths:
paths.remove(path)
paths.append(path)
write_db(paths)
def remove_from_db(path):

0 comments on commit 0d5780c

Please sign in to comment.