Improved cdf function
This commit is contained in:
parent
844fa8070e
commit
385e50a560
1 changed files with 4 additions and 8 deletions
|
|
@ -113,14 +113,10 @@ in
|
||||||
|
|
||||||
# Function to cd to directory containing a file selected with fzf
|
# Function to cd to directory containing a file selected with fzf
|
||||||
function cdf() {
|
function cdf() {
|
||||||
local file
|
local target
|
||||||
file=$(fd "$@" ~ | fzf)
|
target=$(echo "" | fzf --bind "change:reload:fd --hidden --follow --exclude .git {q} ~ 2>/dev/null || true" --header="Type to search, Enter to cd" --preview '([[ -d {} ]] && ls -la {}) || ([[ -f {} ]] && head -20 {})' --height 40% --ansi)
|
||||||
if [[ -n "$file" ]]; then
|
if [[ -n "$target" ]]; then
|
||||||
if [[ -d "$file" ]]; then
|
[[ -d "$target" ]] && cd "$target" || cd "$(dirname "$target")"
|
||||||
cd "$file"
|
|
||||||
else
|
|
||||||
cd "$(dirname "$file")"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue