From 8e84ccb9316d21ba2305e7b40db815be4d947c2c Mon Sep 17 00:00:00 2001 From: Diogo Lemos Date: Thu, 13 Jun 2019 18:17:05 +0100 Subject: [PATCH] fif - add input validation --- Examples.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Examples.md b/Examples.md index 2559c33..2eb4cc0 100644 --- a/Examples.md +++ b/Examples.md @@ -249,7 +249,10 @@ ag --nobreak --nonumbers --noheading . | fzf # using ripgrep combined with preview # find-in-file - usage: fif -fif() { rg --files-with-matches --no-messages $1 | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 $1 || rg --ignore-case --pretty --context 10 $1 {}" } +fif() { + if [ ! "$#" -gt 1 ]; then echo "Need a string to search for!"; return 1; fi + rg --files-with-matches --no-messages $1 | fzf --preview "highlight -O ansi -l {} 2> /dev/null | rg --colors 'match:bg:yellow' --ignore-case --pretty --context 10 $1 || rg --ignore-case --pretty --context 10 $1 {}" +} ``` ### Command history