summaryrefslogtreecommitdiffstatshomepage
path: root/fzf
diff options
context:
space:
mode:
Diffstat (limited to 'fzf')
-rw-r--r--fzf/.config/zsh/.zshrc.d/50-fzf.zsh10
-rwxr-xr-xfzf/.local/bin/live-grep.sh34
2 files changed, 44 insertions, 0 deletions
diff --git a/fzf/.config/zsh/.zshrc.d/50-fzf.zsh b/fzf/.config/zsh/.zshrc.d/50-fzf.zsh
new file mode 100644
index 0000000..c026139
--- /dev/null
+++ b/fzf/.config/zsh/.zshrc.d/50-fzf.zsh
@@ -0,0 +1,10 @@
+#!/bin/zsh
+# vim: ft=sh
+
+_fzf_compgen_path() {
+ fd --hidden --follow --exclude ".git" . "$1"
+}
+
+_fzf_compgen_dir() {
+ fd --type d --hidden --follow --exclude ".git" . "$1"
+}
diff --git a/fzf/.local/bin/live-grep.sh b/fzf/.local/bin/live-grep.sh
new file mode 100755
index 0000000..703297e
--- /dev/null
+++ b/fzf/.local/bin/live-grep.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+need() {
+ for need_cmd in "$@"; do
+ if ! command -v "$need_cmd" >/dev/null 2>&1; then
+ printf "live-grep: command not found: %s\n" "$need_cmd" >&2
+ exit 1
+ fi
+ done
+}
+
+need "rg" "bat"
+
+INITIAL_QUERY="${*:-}"
+RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
+PREVIEW_CMD='bat --color=always {1} --highlight-line {2} 2>/dev/null || bat --color=always {}'
+INITIAL_CMD="$RG_PREFIX --files"
+
+if [ $# -gt 0 ]; then
+ INITIAL_CMD="$RG_PREFIX '$INITIAL_QUERY'"
+fi
+
+# shellcheck disable=2046
+set -- $(
+ FZF_DEFAULT_COMMAND="$INITIAL_CMD" fzf \
+ --ansi --color="hl:-1:underline,hl+:-1:underline:reverse" \
+ --bind="change:reload:sleep 0.1; [ -n {q} ] && ($RG_PREFIX {q} || true) || $RG_PREFIX --files" \
+ --disabled --query="$INITIAL_QUERY" --delimiter=":" \
+ --preview="$PREVIEW_CMD" --preview-window='up,60%,border-bottom,+{2}+3/3,~3'
+)
+
+if [ $# -gt 0 ]; then
+ xdg-open "$1" "+$2"
+fi