From 000e00871830cd15de032c80e2b62946cf19445c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 8 May 2025 18:49:34 -0500 Subject: adding missing dotfiles and folders - profile.d/ - bashrc - authinfo.gpg - .zsh/ --- dotfiles/system/.profile.d/fzf.sh | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 dotfiles/system/.profile.d/fzf.sh (limited to 'dotfiles/system/.profile.d/fzf.sh') diff --git a/dotfiles/system/.profile.d/fzf.sh b/dotfiles/system/.profile.d/fzf.sh new file mode 100644 index 0000000..5a13dd4 --- /dev/null +++ b/dotfiles/system/.profile.d/fzf.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +# fzf.sh +# Craig Jennings +# fuzzy find settings and utilities, sourced by .profile + +### SETTINGS +export FZF_DEFAULT_OPTS='--height=70%' +export FZF_DEFAULT_COMMAND='rg --files' +export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" +export FZF_DEFAULT_COMMAND='rg --files --no-ignore-vcs --hidden' + + +### NAVIGATION + +# cdff - change directory find file +# change to the directory where the file resides. +cdff() { + + file=$(fzf +m -q "$1") + dir=$(dirname "$file") + cd "$dir" || exit +} + +# CD to a directory with fzf +cdd () { + destdir=$(find "${1:-.}" -path '*/\.*' -prune \ + -o -type d -print 2> /dev/null | fzf +m) && + cd "$destdir" +} + +### SYSTEM ADMIN + +# Kill a process with fzf +kp () { + pid=$(ps -ef | sed 1d | eval "fzf ${FZF_DEFAULT_OPTS} -m --header='[kill:process]'" | awk '{print $2}') + + if [ "x$pid" != "x" ] + then + echo "$pid" | xargs kill -${1:-9} + kp + fi +} + +# list available packages, show info in preview, and install selection +yinstall() { + yay -Slq | fzf --multi --preview 'yay -Si {1}' | xargs -ro yay -S --noconfirm +} + + +yinstall-skipverify() { + yay -Slq | fzf --multi --preview 'yay -Si {1}' | xargs -ro yay -S --noconfirm --mflags --skipinteg +} + +# list installed packages, show info in preview, and remove selection +yrm() { + yay -Qq | fzf --multi --preview 'yay -Qi {1}' | xargs -ro yay -Rns +} + +# find-in-file - usage: fif +fif() { + if [ ! "$#" -gt 0 ]; 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' {}" +} + +### CONVENIENCE + +# Find a book in the calibre library and open it in emacs client. +# previously: find ~/books \( -iname \*.epub -o -iname \*.pdf -o -iname \*.djvu \) | fzf | xargs emacs +bk() { + bkfile=$(find ~/sync/books/ \( -iname "*.pdf" -o -iname "*.epub" -o -iname "*.djvu" \) -print | fzf) + if [ -n "$bkfile" ]; then + emacsclient -c -a '' "$bkfile" & + fi +} + -- cgit v1.2.3