aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/system/.profile.d/fzf.sh
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-01-24 18:52:34 -0600
committerCraig Jennings <c@cjennings.net>2026-01-24 18:52:34 -0600
commit7d0f90da66985b402c6a25eb3eca8cc9e6060ced (patch)
tree94a4fefdccc5cc1750a7466b3764b44bf1b8d0b0 /dotfiles/system/.profile.d/fzf.sh
downloadarchsetup-7d0f90da66985b402c6a25eb3eca8cc9e6060ced.tar.gz
archsetup-7d0f90da66985b402c6a25eb3eca8cc9e6060ced.zip
fix(testing): remove obsolete --skip-slow-packages option
This flag was removed from archsetup but remained in test scripts.
Diffstat (limited to 'dotfiles/system/.profile.d/fzf.sh')
-rw-r--r--dotfiles/system/.profile.d/fzf.sh123
1 files changed, 123 insertions, 0 deletions
diff --git a/dotfiles/system/.profile.d/fzf.sh b/dotfiles/system/.profile.d/fzf.sh
new file mode 100644
index 0000000..5fab752
--- /dev/null
+++ b/dotfiles/system/.profile.d/fzf.sh
@@ -0,0 +1,123 @@
+#!/bin/sh
+
+# fzf.sh
+# Craig Jennings <c@cjennings.net>
+# fuzzy find settings and utilities, sourced by .profile
+
+# otherwise ** doesn't expand
+source /usr/share/fzf/completion.zsh
+
+### 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'
+
+# Directory paths for convenience functions
+IF_GAMES_DIR="$HOME/sync/org/text.games"
+BOOKS_DIR="$HOME/sync/books"
+
+### 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 <searchTerm>
+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 an epub book in the library and open it in epr terminal reader.
+# previously: find ~/books \( -iname \*.epub -o -iname \*.pdf -o -iname \*.djvu \) | fzf | xargs emacs
+bk() {
+ bkfile=$(find "$BOOKS_DIR" -iname "*.epub" -print | fzf)
+ if [ -n "$bkfile" ]; then
+ epr "$bkfile"
+ fi
+}
+
+# Find an interactive fiction game and open it in frotz.
+# Supports Z-machine files (.z1-.z8, .zblorb, .blorb)
+tg() {
+ gamefile=$(find "$IF_GAMES_DIR" -type f \( -iname "*.z[1-8]" -o -iname "*.zblorb" -o -iname "*.blorb" \) -print | fzf)
+ if [ -n "$gamefile" ]; then
+ frotz "$gamefile"
+ fi
+}
+
+
+
+# close wireguard connection first if already running, then
+# run wireguard, selecting the configuration file.
+wgup() {
+ # Check if wireguard is running
+ output=$(sudo wg)
+ if [[ -n "$output" ]]; then
+ # Shutdown all wg interfaces if WireGuard is currently running.
+ for iface in $(sudo wg show interfaces); do
+ sudo wg-quick down "${iface}"
+ done
+ fi
+ # Get the list of config files
+ wgfile=$(sudo find /etc/wireguard/ -iname "*.conf" -exec basename -s .conf {} \; | fzf)
+
+ if [ -n "$wgfile" ]; then
+ sudo wg-quick up $wgfile
+ sudo wg
+ fi
+}
+wgdown() {
+ # Check if wireguard is running
+ output=$(sudo wg)
+ if [[ -n "$output" ]]; then
+ # Shutdown all wg interfaces if WireGuard is currently running.
+ for iface in $(sudo wg show interfaces); do
+ sudo wg-quick down "${iface}"
+ done
+ fi
+}
+alias wg=wgup