summaryrefslogtreecommitdiff
path: root/dotfiles
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-05-27 17:50:58 -0500
committerCraig Jennings <c@cjennings.net>2025-05-27 17:50:58 -0500
commit77deca928801efd333089ff01a5b9e3e20e11205 (patch)
tree7395f26920bcc6592ba3923d74f6822bd423f1b9 /dotfiles
parent56a95d0835469438dc8538642e6d349b33dd463d (diff)
add wireguard fzf functionality and install script
Diffstat (limited to 'dotfiles')
-rw-r--r--dotfiles/system/.profile.d/fzf.sh69
1 files changed, 45 insertions, 24 deletions
diff --git a/dotfiles/system/.profile.d/fzf.sh b/dotfiles/system/.profile.d/fzf.sh
index 5a13dd4..2193614 100644
--- a/dotfiles/system/.profile.d/fzf.sh
+++ b/dotfiles/system/.profile.d/fzf.sh
@@ -4,73 +4,94 @@
# 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'
-
-### NAVIGATION
+### 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
+ 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"
+ 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}')
+ 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
+ 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
+ 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
+ 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
+ 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' {}"
+ 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
+### 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
+ bkfile=$(find ~/sync/books/ \( -iname "*.pdf" -o -iname "*.epub" -o -iname "*.djvu" \) -print | fzf)
+ if [ -n "$bkfile" ]; then
+ emacsclient -c -a '' "$bkfile" &
+ fi
}
+# close wireguard connection first if already running, then
+# run wireguard, selecting the configuration file.
+wg() {
+ # 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
+}