Add fzf and 'gf' (git (vim) file)
dblume

dblume commited on 2025-12-12 12:19:54
Showing 1 changed files, with 21 additions and 0 deletions.


Haven't tested this on macOS. Not sure about gf as the command,
might be better as "vf" (vim file) or "vg" (vim git file)?
... ...
@@ -160,6 +160,27 @@ case "$-" in
160 160
 
161 161
   # Enables recursive matches: ls -l **/*.png
162 162
   shopt -s globstar
163
+
164
+  # fzf: macOS install with brew; Linux install with git clone to ~/.fzf
165
+  if [ -f ~/.fzf.bash ]; then
166
+    source ~/.fzf.bash
167
+
168
+    gf() {
169
+      local file
170
+      if type batcat >/dev/null 2>&1; then
171
+        file="$(git ls-files | fzf --preview 'batcat --color=always --wrap never --line-range :$(($LINES - 4)) {}' --preview-window=right:60%)"
172
+      else
173
+        file="$(git ls-files | fzf --preview 'head -n $LINES {}' --preview-window=right:60%)"
174
+      fi
175
+      [ -n "$file" ] && ${EDITOR:-vim} "$file"
176
+    }
177
+
178
+  fi
179
+
180
+  # bat may be installed as "bat" (macOS) or "batcat" (Debian/Ubuntu)
181
+  if type batcat >/dev/null 2>&1; then
182
+    alias bat='batcat'
183
+  fi
163 184
  ;;
164 185
 esac
165 186
 
166 187