From 55d0392a072fd94bd811e218070b1963c1fbbbe8 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Tue, 8 Aug 2023 00:20:10 +0100 Subject: [PATCH] Add edit() function to find and edit file --- .config/scripts/functions/fzf | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.config/scripts/functions/fzf b/.config/scripts/functions/fzf index e6fcede..b19ec9f 100644 --- a/.config/scripts/functions/fzf +++ b/.config/scripts/functions/fzf @@ -3,8 +3,8 @@ # These are functions related to fzf used to go to locations, edit # configurations, or start a tmux session in common directories. -# Finds within current directory and cd into the location of the file or -# directory. +# Finds recursively within current directory and cd into the location of the +# file or directory. goto() { path=$(find $1 2> /dev/null | fzf) @@ -12,6 +12,14 @@ goto() cd "$path" } +# Finds files recursively within current directory and edits file. +edit() +{ + file=$(find $1 -type f 2> /dev/null | fzf) + [ -z "$file" ] && return + $EDITOR "$file" +} + # Quickly find and edit a file within ~/.config or ~/Documents cfg() {