Commit 6aefa34

Eric Bower  ·  2026-09-08 23:49:04 -0400 EDT
parent 88b5567
feat(fzf): scripts ftags and fcd
2 files changed,  +75, -0
+64, -0
 1@@ -0,0 +1,64 @@
 2+#!/usr/bin/env bash
 3+set -euo pipefail
 4+
 5+git_root="$(git rev-parse --show-toplevel 2>/dev/null || true)"
 6+
 7+tag_files=()
 8+if [[ $# -gt 0 ]]; then
 9+  tag_files=("$@")
10+else
11+  for f in tags .tags_deps; do
12+    [[ -f "$f" ]] && tag_files+=("$f")
13+  done
14+  if [[ ${#tag_files[@]} -eq 0 && -n "$git_root" ]]; then
15+    for f in "$git_root/tags" "$git_root/.tags_deps"; do
16+      [[ -f "$f" ]] && tag_files+=("$f")
17+    done
18+  fi
19+fi
20+
21+if [[ ${#tag_files[@]} -eq 0 ]]; then
22+  echo "ftags: no tags file found (try: ftags <tagfile>)" >&2
23+  exit 1
24+fi
25+
26+load_tags() {
27+  for tf in "${tag_files[@]}"; do
28+    readtags -t "$tf" -e -n -l 2>/dev/null || true
29+  done
30+}
31+
32+selected="$(load_tags | awk -F'\t' '{
33+  line = 1
34+  kind = ""
35+  for (i = 4; i <= NF; i++) {
36+    if ($i ~ /^line:/) { line = substr($i, 6) }
37+    else if ($i ~ /^kind:/) { kind = substr($i, 6) }
38+  }
39+  printf "%-28s %-5s %s\t%s\t%s\n", $1, kind, $2, $2, line
40+}' | fzf \
41+  --delimiter=$'\t' \
42+  --with-nth=1 \
43+  --border=sharp \
44+  --pointer='>' \
45+  --preview='f={2}; [ ! -f "$f" ] && [ -n "'"$git_root"'" ] && f="'"$git_root"'/$f"; bat --style=numbers --color=always --wrap=never -H {3} "$f" 2>/dev/null || cat "$f" 2>/dev/null' \
46+  --preview-window='right,60%,+{3}-10,border-sharp,nowrap,<80(up,50%,border-sharp,nowrap)' \
47+  --bind='ctrl-/:toggle-preview' \
48+  --prompt='tags> ' || true)"
49+
50+[[ -z "$selected" ]] && exit 0
51+
52+file="$(printf '%s' "$selected" | cut -f2)"
53+line="$(printf '%s' "$selected" | cut -f3)"
54+
55+if [[ ! -f "$file" && -n "$git_root" && -f "$git_root/$file" ]]; then
56+  file="$git_root/$file"
57+fi
58+
59+editor="${EDITOR:-kak}"
60+
61+if [[ -n "$line" && "$line" -gt 1 ]]; then
62+  exec "$editor" "+$line" "$file"
63+else
64+  exec "$editor" "$file"
65+fi
+11, -0
 1@@ -34,6 +34,17 @@ pw() {
 2   tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c 20; echo
 3 }
 4 
 5+fcd() {
 6+  local dir
 7+  if command -v fd >/dev/null 2>&1; then
 8+    dir="$(fd --max-depth 3 --type d --hidden --follow --exclude .git --exclude .jj . "${1:-.}" 2>/dev/null | fzf +m)" || return
 9+  else
10+    dir="$(find "${1:-.}" -mindepth 1 -maxdepth 3 -path '*/.*' -prune -o -type d -print 2>/dev/null | fzf +m)" || return
11+  fi
12+  test -n "$dir" && cd "$dir"
13+}
14+
15+
16 _zmx_env_hook() {
17   if test -n "${ZMX_SESSION:-}"; then
18     eval "$(zmx print-env -s .)"