vv: New vi alias that stay in current dir

This commit is contained in:
gardouille 2024-10-29 15:27:47 +01:00
parent ff3b496927
commit abae88e392
Signed by: gardouille
GPG Key ID: E759BAA22501AF32

30
zshrc
View File

@ -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 {{{