From 0e80fa3b8fde5094839499bb182783170f351b15 Mon Sep 17 00:00:00 2001
From: Daniel Lundin <daniel@arity.se>
Date: Fri, 4 Mar 2022 12:11:00 +0100
Subject: [PATCH] Use fre+fzf to edit any file in a git repo, with frecency
 history

---
 .zshrc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/.zshrc b/.zshrc
index 627d925..add0f7e 100644
--- a/.zshrc
+++ b/.zshrc
@@ -129,7 +129,15 @@ export NVIM_LISTEN_ADDRESS=/tmp/nvimsocket
 
 e ()
 {
-  nvr --nostart --remote $(readlink -f "$@")
+  if [ -n "$1" ]; then
+    _file=$(readlink -f "$@") 
+  else
+    _git_root=$(git rev-parse --show-toplevel)
+    _store=$(printf $_git_root | sha1sum | cut -d ' ' -f 1)
+    _file=$( (fre --store_name $_store --sorted && fd --type f --hidden --follow --exclude .git . $_git_root) | fzf-tmux)
+    fre --store_name $_store --add $_file
+  fi
+  nvr --nostart --remote $_file
 	tmux select-window -t1
 }