diff options
| author | Craig Jennings <c@cjennings.net> | 2026-01-26 16:57:37 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-01-26 16:57:37 -0600 |
| commit | 7d490453085ae084ce0e3875952eae1d3ad7b1ab (patch) | |
| tree | d6f76ded02d541107271dc2b04cac34435c81a26 /dotfiles/system/.zshrc.d/fzf.sh | |
| parent | feb8dfaae9b0172c9d24e7e0d115754a467b4627 (diff) | |
refactor(shell): reorganize shell config for proper separation
Restructure shell configuration to follow standard conventions:
- .profile: Environment variables only (POSIX compatible)
- .bash_profile: NEW - sources .profile and .bashrc for login shells
- .bashrc: Bash-specific settings, sources .bashrc.d/
- .zshrc: Zsh-specific settings, sources .zshrc.d/
New modular directories:
- .bashrc.d/: aliases, emacs, fzf, git, media, utilities
- .zshrc.d/: same as bashrc.d plus arch-downgrade (zsh-only)
- .profile.d/: reduced to env-only files (display, framework, auto-tmux)
Fixes:
- Remove duplicate .profile sourcing in .bashrc
- Remove broken XDG_CURRENT_DESKTOP=GNOME line from display.sh
- Move aliases/functions from .profile to appropriate .d/ directories
- Shell-specific init (zoxide, fzf) now in .bashrc/.zshrc directly
- FreeBSD bindkey fix now in .zshrc directly
Also adds CLAUDE.md session context file.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'dotfiles/system/.zshrc.d/fzf.sh')
| -rw-r--r-- | dotfiles/system/.zshrc.d/fzf.sh | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/dotfiles/system/.zshrc.d/fzf.sh b/dotfiles/system/.zshrc.d/fzf.sh new file mode 100644 index 0000000..9a5a9bd --- /dev/null +++ b/dotfiles/system/.zshrc.d/fzf.sh @@ -0,0 +1,122 @@ +# fzf.sh +# Craig Jennings <c@cjennings.net> +# FZF settings and utility functions + +# ============================================================================= +# Settings +# ============================================================================= +export FZF_DEFAULT_OPTS='--height=70%' +export FZF_DEFAULT_COMMAND='rg --files --no-ignore-vcs --hidden' +export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" + +# Directory paths for convenience functions +IF_GAMES_DIR="$HOME/sync/org/text.games" +BOOKS_DIR="$HOME/sync/books" + +# ============================================================================= +# Navigation +# ============================================================================= + +# cdff - change directory to where a file resides +cdff() { + file=$(fzf +m -q "$1") + dir=$(dirname "$file") + cd "$dir" || return 1 +} + +# cdd - cd to directory with fzf +cdd() { + destdir=$(find "${1:-.}" -path '*/\.*' -prune \ + -o -type d -print 2>/dev/null | fzf +m) && + cd "$destdir" +} + +# ============================================================================= +# System Admin +# ============================================================================= + +# Kill process with fzf +kp() { + pid=$(ps -ef | sed 1d | eval "fzf ${FZF_DEFAULT_OPTS} -m --header='[kill:process]'" | awk '{print $2}') + if [ -n "$pid" ]; then + echo "$pid" | xargs kill -"${1:-9}" + kp + fi +} + +# Install packages with fzf preview +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 +} + +# Remove packages with fzf preview +yrm() { + yay -Qq | fzf --multi --preview 'yay -Qi {1}' | xargs -ro yay -Rns +} + +# Find in file with fzf +fif() { + if [ "$#" -eq 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 and read epub book in terminal +bk() { + bkfile=$(find "$BOOKS_DIR" -iname "*.epub" -print | fzf) + if [ -n "$bkfile" ]; then + epr "$bkfile" + fi +} + +# Find and play interactive fiction game +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 +} + +# ============================================================================= +# WireGuard +# ============================================================================= + +wgup() { + # Shutdown existing connections first + output=$(sudo wg 2>/dev/null) + if [ -n "$output" ]; then + for iface in $(sudo wg show interfaces); do + sudo wg-quick down "${iface}" + done + fi + # Select and start new connection + 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() { + output=$(sudo wg 2>/dev/null) + if [ -n "$output" ]; then + for iface in $(sudo wg show interfaces); do + sudo wg-quick down "${iface}" + done + fi +} + +alias wg=wgup |
