From 1600648e3f28de688170ab4a8a579da8d6115d15 Mon Sep 17 00:00:00 2001 From: Sirisak Lueangsaksri <1087399+spywhere@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:45:59 +0700 Subject: [PATCH] feat(binaries): add local project navigation --- binaries/navigate | 36 ++++++++++++++++++++++++++++++++++++ configs/zsh/aliases | 1 + 2 files changed, 37 insertions(+) create mode 100755 binaries/navigate diff --git a/binaries/navigate b/binaries/navigate new file mode 100755 index 0000000..35e161f --- /dev/null +++ b/binaries/navigate @@ -0,0 +1,36 @@ +#!/bin/bash + +if test "${BASH_SOURCE[0]}" = "$0"; then + echo "ERROR: This command must be sourced" + echo "It can be setup as an alias like this:" + echo " alias $(basename "$0")=\". $(basename "$0")\"" + exit 1 +fi + +query="" + +command="cd" +if ! test -t 1; then + command="echo" +fi + +if test "$1" = "-"; then + root="$(git rev-parse --show-toplevel 2>/dev/null)" + if test -n "$root"; then + "$command" "$root" || exit + else + echo "ERROR: Cannot infer root directory as working directory is not in a git project" + fi + return +elif test -n "$@"; then + query="-q $*" +fi + +bfs() { + for i in $(seq 1 5); do + find . -type d -mindepth "$i" -maxdepth "$i" -not -name . + done + find . -type d -mindepth 5 -not -name . +} + +"$command" "$(bfs | cut -d'/' -f2- | fzf --height=20 '--preview=ls -1 {}' '--bind=ctrl-/:toggle-preview' "$query")" || exit diff --git a/configs/zsh/aliases b/configs/zsh/aliases index f759be2..db053af 100644 --- a/configs/zsh/aliases +++ b/configs/zsh/aliases @@ -4,6 +4,7 @@ alias resume="fg" # quick project switching alias w=". work" +alias c=". navigate" # git alias glgfp="glg --first-parent"