summary refs log tree commit diff
path: root/dot_local/share/zsh/fzf
diff options
context:
space:
mode:
authorAlen <alen@dotfiles.xyz>2025-01-19 03:26:44 +0400
committerAlen <alen@dotfiles.xyz>2025-01-19 03:26:44 +0400
commit43c982798c902315aba2f8865d0407c6ff70a180 (patch)
tree469de00c188d60d2859066cfa94bf2880b16eb46 /dot_local/share/zsh/fzf
parent6e8b63f101e056f80cf6b7d17d07161bead1ceeb (diff)
Add batch of zsh plugins and kitting out
Diffstat (limited to 'dot_local/share/zsh/fzf')
-rw-r--r--dot_local/share/zsh/fzf/fzf.plugin.zsh90
1 files changed, 90 insertions, 0 deletions
diff --git a/dot_local/share/zsh/fzf/fzf.plugin.zsh b/dot_local/share/zsh/fzf/fzf.plugin.zsh
new file mode 100644
index 0000000..70f73b9
--- /dev/null
+++ b/dot_local/share/zsh/fzf/fzf.plugin.zsh
@@ -0,0 +1,90 @@
+ftop() {
+    FZF_DEFAULT_COMMAND='ps -ef' \
+      fzf --bind 'ctrl-r:reload(ps -ef)' \
+          --header 'Press CTRL-R to reload' \
+          --header-lines=1 \
+          --height=50% --layout=reverse
+}
+
+__fzf-jump-widget() {
+    LBUFFER="${LBUFFER}$(fasd -ld | tac | fzf)"
+    local ret=$?
+    zle redisplay
+    if [[ $ret == 0 ]]; then
+        zle accept-line
+    fi
+    return $ret
+}
+
+zle -N __fzf-jump-widget
+
+__fzf-open-widget() {
+    FILE=$(fasd -lf | tac | fzf)
+    local ret=$?
+    if [[ $ret != 0 ]]; then
+        return $ret
+    fi
+    if [[ "${LBUFFER}" != "" ]]; then
+        LBUFFER="${LBUFFER}${FILE}"
+    elif [[ $(file --mime ${FILE}) =~ "binary" ]]; then
+        LBUFFER="xdg-open ${FILE}"
+    else
+        LBUFFER="${EDITOR} ${FILE}"
+    fi
+    zle redisplay
+    if [[ $ret == 0 ]]; then
+        zle accept-line
+    fi
+    return $ret
+}
+
+zle -N __fzf-open-widget
+
+# Search files with preview
+__fzf-preview-widget() {
+    LBUFFER="${LBUFFER}$(ls | fzf -e --preview=${FZF_BAT_PREVIEW})"
+}
+zle -N __fzf-preview-widget
+
+# rg on Asteroids
+rf() {
+    RG_PREFIX="rga --files-with-matches"
+    local file
+    file="$(
+        FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
+            fzf --sort --preview="[[ ! -z {} ]] && echo {} && rga --pretty --context 5 {q} {}" \
+                --phony -q "$1" \
+                --bind "change:reload:$RG_PREFIX {q}" \
+                --preview-window="70%:wrap"
+    )" &&
+    echo $file
+    # echo "opening $file" &&
+    # xdg-open "$file"
+}
+
+# Fancy git diff using fzf
+if which git &>/dev/null; then
+    alias gdf='
+        git status -s \
+         | fzf --no-sort --reverse \
+         --preview "git diff --color=always {+2} | delta" \
+         --bind=ctrl-j:preview-down --bind=ctrl-k:preview-up \
+         --preview-window=right:70%:wrap'
+fi
+
+# figure out some useful things to do...
+# https://junegunn.kr/2016/07/fzf-git/
+_FZF_BAT_PREVIEW='[[ $(file --mime {}) =~ "binary" ]] && echo "<folder/binary file>" || bat --style=numbers --color=always {} --line-range :500'
+alias fzfp="fzf --preview='${_FZF_BAT_PREVIEW}'"
+alias fzfd="fzf --preview='${_FZF_BAT_PREVIEW}' --bind='enter:execute(bat --style=numbers --color=always --paging=always {}),ctrl-e:execute(micro {}),tab:toggle-preview'"
+
+export FZF_DEFAULT_OPTS="-1 --height 50% --layout=reverse --border --multi --info=inline"
+
+# Use fd/rg/ag if possible to follow any ignores / sensible configs
+if which fd &>/dev/null; then
+    export FZF_DEFAULT_COMMAND='fd --type f'
+elif which rg &>/dev/null; then
+    export FZF_DEFAULT_COMMAND='rg --files'
+elif which ag &>/dev/null; then
+    export FZF_DEFAULT_COMMAND='ag --files-with-matches'
+fi