From 68df5039da360033c3ab69e5f1a08e4e73f37b11 Mon Sep 17 00:00:00 2001 From: Guy Stan Date: Thu, 23 Jul 2020 18:49:37 +0100 Subject: [PATCH] Updated Examples (markdown) --- Examples.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Examples.md b/Examples.md index 8a5369a..c23ed7b 100644 --- a/Examples.md +++ b/Examples.md @@ -295,8 +295,6 @@ fif() { } ``` -Suggested by [@gbstan](https://github.com/gbstan) - ```sh # alternative using ripgrep-all (rga) combined with fzf-tmux preview # implementation below makes use of "open" on macOS, which can be replaced by other commands if needed. @@ -305,10 +303,26 @@ Suggested by [@gbstan](https://github.com/gbstan) fif() { if [ ! "$#" -gt 0 ]; then echo "Need a string to search for!"; return 1; fi local file - file="$(rga --max-count=1 --ignore-case --files-with-matches --no-messages "$@" | fzf-tmux +m --preview="rga --ignore-case --pretty --context 10 '"$@"' {}")" && open "$file" + file="$(rga --max-count=1 --ignore-case --files-with-matches --no-messages "$*" | fzf-tmux +m --preview="rga --ignore-case --pretty --context 10 '"$*"' {}")" && echo "opening $file" && open "$file" || return 1; } ``` +Suggested by [@gbstan](https://github.com/gbstan) + +```sh +# alternative using ripgrep-all (rga) combined with sk preview +# This requires sk (skim) installed: https://github.com/lotabout/skim +# This will open the selected entry with SublimeText at the precise line and column where the entry is +# skrga: rga + subl - usage: skrga or skrga match_in_content_of_files or skgra regex_match_in_content_of_files +# If you provide arguments to skrga you can then use ctrl+q on the list of matches to filter with patterns appearing in each of the lines returned by sk +skrga() { + local file + file="$(sk-tmux --bind "ctrl-p:toggle-preview" --ansi -i --cmd-query "$*" -c 'rga --ignore-case --color=always --line-number --column {}' --preview 'bat --color=always --style=header,numbers --highlight-line "$(echo {1}|cut -d: -f2)" --line-range "$(($(echo {1}|cut -d: -f2))):$(($(echo {1}|cut -d: -f2)+50))" "$(echo {1}|cut -d: -f1)"')"; [[ $? -eq 0 ]] && echo "opening $file" && subl "$(echo "$file"|cut -d: -f1):$(echo "$file"|cut -d: -f2):$(echo "$file"|cut -d: -f3)" || return 1; +} +``` + +Suggested by [@gbstan](https://github.com/gbstan) + ```sh #!/bin/bash