Skip to content

Commit e42b744

Browse files
committed
feat(dev): prettify paths in fzf
1 parent 86a8fd9 commit e42b744

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dev/script.bash

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,7 @@ function main() {
1111
local selected_path
1212
selected_path=$(select_path "$project_paths")
1313

14-
if [[ -z "$selected_path" ]]; then
15-
exit 1
16-
fi
17-
18-
cd "$selected_path" || exit 1
19-
20-
if [ -n "$VISUAL" ]; then
21-
"$VISUAL" .
22-
exit 0
23-
fi
24-
25-
if [ -n "$EDITOR" ]; then
26-
"$EDITOR" .
27-
exit 0
28-
fi
14+
open_path "$selected_path"
2915
}
3016

3117
function find_search_paths() {
@@ -40,8 +26,39 @@ function find_project_paths() {
4026
}
4127

4228
function select_path() {
43-
local paths="$1"
44-
echo "$paths" | sed 's|.*/\([^/]*\)|\1 (\0)|' | fzf --ansi --border=none | sed -n 's/.*(\(.*\)).*/\1/p'
29+
local project_paths="$1"
30+
local pretty_project_paths
31+
pretty_project_paths=$(make_pretty_paths "$project_paths")
32+
33+
echo "$pretty_project_paths" |
34+
fzf --ansi --border=none --info=inline |
35+
sed -n 's/.*(\(.*\)).*/\1/p'
36+
}
37+
38+
function make_pretty_paths() {
39+
echo "$1" |
40+
awk '{ cmd = "basename " $1; cmd | getline base; close(cmd); printf "%s (%s)\n", base, $1 }' |
41+
awk 'BEGIN { gray="\033[90m"; blue="\033[34m"; reset="\033[0m"; folderIcon=" "; } { print blue folderIcon $1 reset " " gray ""$2"" reset }'
42+
}
43+
44+
function open_path() {
45+
local path="$1"
46+
47+
if [[ -z "$path" ]]; then
48+
exit 1
49+
fi
50+
51+
cd "$path" || exit 1
52+
53+
if [ -n "$VISUAL" ]; then
54+
"$VISUAL" .
55+
exit 0
56+
fi
57+
58+
if [ -n "$EDITOR" ]; then
59+
"$EDITOR" .
60+
exit 0
61+
fi
4562
}
4663

4764
main

0 commit comments

Comments
 (0)