diff --git a/zshrc b/zshrc index ea44ae0..e780a44 100644 --- a/zshrc +++ b/zshrc @@ -2287,6 +2287,36 @@ function v() { ## }}} } # }}} +# vv - fuzzy open file with vi and stay to current directory {{{ +# Search with fd (fdfind is perfect to search more than ~200k files) +# Check for symlinked files too +# Allow to give arguments to prefill fzf request +# Display the 50 first lines of the selected file with bat (batcat) +# Move to the directory of the selected file +# Open the selected file with vi +function vv() { + local files + local file + + ## Manage argument {{{ + if [ "${#}" -eq "0" ]; then + ## Default command without args + files=$(fd --hidden --no-ignore --exclude .git/ --type file --type symlink --follow | fzf --prompt='vi> ' --preview 'bat --color=always --theme="OneHalfLight" --line-range 0:50 {}' --no-multi) && + else + ## If at least one argument was given, add it to fzf query + files=$(fd --hidden --no-ignore --exclude .git/ --type file --type symlink --follow | fzf --prompt='vi> ' --preview 'bat --color=always --theme="OneHalfLight"--line-range 0:50 {}' --no-multi --query "${*} ") && + fi + ## }}} + + ## Move to the directory and open the file {{{ + if [[ -n "${files}" ]] + then + file="${files}" + vi -- "${file}" + fi + ## }}} +} +# }}} # fssh - fuzzy ssh {{{ # Ensure to have __fzf_list_hosts FZF function {{{