Add edit() function to find and edit file

This commit is contained in:
Sheldon Lee 2023-08-08 00:20:10 +01:00
parent 8877db9b16
commit 55d0392a07

View File

@ -3,8 +3,8 @@
# These are functions related to fzf used to go to locations, edit # These are functions related to fzf used to go to locations, edit
# configurations, or start a tmux session in common directories. # configurations, or start a tmux session in common directories.
# Finds within current directory and cd into the location of the file or # Finds recursively within current directory and cd into the location of the
# directory. # file or directory.
goto() goto()
{ {
path=$(find $1 2> /dev/null | fzf) path=$(find $1 2> /dev/null | fzf)
@ -12,6 +12,14 @@ goto()
cd "$path" 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 # Quickly find and edit a file within ~/.config or ~/Documents
cfg() cfg()
{ {