~kris/dots

srice

srice/.local/bin/proj -rw-r--r-- 583 bytes
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month ago
                                                                                
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
#!/bin/sh
# proj -- fuzzy project switcher for ~/dev
# Usage: proj [query]
# Requires: fzf, eza

DEV_DIR="$HOME/dev"

if [ -n "$1" ]; then
    # direct match
    target="$DEV_DIR/$1"
    if [ -d "$target" ]; then
        cd "$target"
        echo "$target"
        exit 0
    fi
fi

# fuzzy select
dir=$(find "$DEV_DIR" -maxdepth 1 -type d | sort |
    sed "s|$DEV_DIR/||" | tail -n +2 |
    fzf --preview "eza --tree --icons --level=2 --color=always $DEV_DIR/{}" \
        --preview-window 'right:50%' \
        --query "${1:-}")

if [ -n "$dir" ]; then
    echo "$DEV_DIR/$dir"
fi