From 3bffa00e0ab087ed80b4aeebbe5365558c2c388b Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Fri, 18 Nov 2022 20:17:48 +0000 Subject: [PATCH] Added fzf functions. --- .config/scripts/functions/fzf | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .config/scripts/functions/fzf diff --git a/.config/scripts/functions/fzf b/.config/scripts/functions/fzf new file mode 100644 index 0000000..7b2b84b --- /dev/null +++ b/.config/scripts/functions/fzf @@ -0,0 +1,30 @@ +#!/bin/bash +# +# 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. +goto() +{ + path=$(find $1 | fzf) + [ -f "$path" ] && path=$(dirname "$path") + cd "$path" +} + +# Quickly find and edit a file within ~/.config or ~/Documents +cfg() +{ + file=$(find $HOME/.config $HOME/Documents -type f | fzf) + [ -z "$file" ] && return + $EDITOR "$file" +} + +# Quickly find a directory within ~/.config or ~/Documents and start a tmux +# session there with the name of the directory. +ts() +{ + dir=$(find $HOME/.config $HOME/Documents -type d | fzf) + [ -z "$dir" ] && return + tmux new -s $(basename "$dir") -c "$dir" +}