From 78f5051503a79b0a3334626e07ffab6f156d66bc Mon Sep 17 00:00:00 2001 From: Matthew Bennett Date: Sat, 17 Oct 2020 17:34:55 +0200 Subject: [PATCH] Updated Examples (markdown) --- Examples.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Examples.md b/Examples.md index 6c4b9e0..c561ee8 100644 --- a/Examples.md +++ b/Examples.md @@ -120,6 +120,34 @@ fo() { } ``` +```sh +# select files with fzf and send to command. +# Put non-GUI processes in the foreground +f() { + # store the files from fzf + IFS=$'\n' files=($(fzf --query="$2" --multi)) + + # if no files passed (e.g. if Esc pressed), return to terminal + if [ -z "${files}" ]; then + return 1 + fi + + # send the files to a program + # some programs should not be run as background + if ! [[ $1 =~ ^(cd)$ ]]; then + $1 "${files[@]}" & + else + $1 "${files[@]}" + fi + + # if the program is not on the list of GUIs (e.g. vim, cat, etc.) bring it + # to foreground so we can see the output + if ! [[ $1 =~ ^(zathura|vlc)$ ]]; then + fg %% + fi +} +``` + ```sh # vf - fuzzy open with vim from anywhere # ex: vf word1 word2 ... (even part of a file name)