Skip to content

Instantly share code, notes, and snippets.

@Medialo
Created March 19, 2026 19:45
Show Gist options
  • Select an option

  • Save Medialo/921ddfa5bb8e1df4a25ccb9eb503fa98 to your computer and use it in GitHub Desktop.

Select an option

Save Medialo/921ddfa5bb8e1df4a25ccb9eb503fa98 to your computer and use it in GitHub Desktop.
export PATH="/home/paul.brelet@sglk.local/.cargo/bin:$PATH"
#BIND_EXECUTE="--bind 'right:execute(echo "{}" > /dev/tty)+abort'"
function find_folder() {
local start_dir="${1:-.}" # prend le premier argument, ou '.' par défaut
find "$start_dir" -type d | fzf --preview='tree -C {} | head -50'
}
export FZF_START="fzf --style full"
function bind_execute() {
echo "pwd: $(pwd)"
echo "Opening: ${1}"
if [[ -f "${1}" ]]; then
echo "${1} is a file, opening with code"
code "${1}"
elif [[ -d "${1}" ]]; then
echo "${1} is a directory, changing directory"
pb_lacy_dir "$(pwd)" "${1}"
else
echo "Error: ${1} is neither a file nor a directory"
return 1
fi
}
function pb_lacy_dir() {
path=$(realpath --relative-to=${1} ${2})
echo "path: $path"
selected_path=$(find "$path" | $FZF_START --bind 'enter:accept' --bind "right:execute(bind_execute "${1}/{}")+abort" --preview="if [ -d {} ]; then tree -L 2 -C {}; else cat {}; fi")
if [[ -d "$1/$selected_path" ]]; then
cd "$1/$selected_path" || return
echo "Changed directory to: $1/$selected_path"
else
echo "No selection made, staying in: $(pwd)"
fi
return 0
}
function yy() {
# if no argument is provided,
if [ $# -eq 0 ]; then
builtin cd
else
y "$@"
fi
}
export -f bind_execute
export -f pb_lacy_dir
eval "$(lacy init bash --cd-cmd="builtin cd" --custom-fuzzy="$FZF_START --bind 'right:execute(pb_lacy_dir $(pwd) "{}")+abort' --preview='tree -L 2 -C {} | head -50'")"
alias cd='yy'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment