diff --git a/zshrc b/zshrc index c0e3e6f..aaad2b5 100644 --- a/zshrc +++ b/zshrc @@ -282,8 +282,28 @@ load-nvmrc() { add-zsh-hook chpwd load-nvmrc load-nvmrc -# fdp - cd to selected parent directory -fdp() { +# fe [FUZZY PATTERN] - Open the selected file with the default editor +# - Bypass fuzzy finder if there's only one match (--select-1) +# - Exit if there's no match (--exit-0) +fe() { + IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0)) + [[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}" +} + +# Modified version where you can press +# - CTRL-O to open with `open` command, +# - CTRL-E or Enter key to open with the $EDITOR +fo() { + IFS=$'\n' out=("$(fzf-tmux --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)") + key=$(head -1 <<< "$out") + file=$(head -2 <<< "$out" | tail -1) + if [ -n "$file" ]; then + [ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file" + fi +} + +# fdr - cd to selected parent directory +fdr() { local declare dirs=() get_parent_dirs() { if [[ -d "${1}" ]]; then dirs+=("$1"); else return; fi @@ -349,9 +369,10 @@ fshow() { } # Search z history with fzf -fz() { +unalias z 2> /dev/null +z() { [ $# -gt 0 ] && _z "$*" && return - cd "$(_z -l 2>&1 | fzf-tmux +s --tac --query "$*" | sed 's/^[0-9,.]* *//')" + cd "$(_z -l 2>&1 | fzf --height 40% --nth 2.. --reverse --inline-info +s --tac --query "${*##-* }" | sed 's/^[0-9,.]* *//')" } # Browse Brave history