2021-09-18 21:04:50 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Find and edit config files utilizing fzf
|
2021-09-18 21:09:40 +00:00
|
|
|
alias dedup='awk '"'"'!a[$0]++'"'"
|
2021-09-20 06:56:42 +00:00
|
|
|
|
2021-09-18 21:04:50 +00:00
|
|
|
listconf() {
|
2021-09-21 20:51:19 +00:00
|
|
|
{ cat "$conf_cache";
|
2021-09-21 21:18:44 +00:00
|
|
|
fd --hidden --type file --size -1m --max-depth 1 . ~;
|
2021-09-21 21:10:39 +00:00
|
|
|
find "${XDG_CONFIG_HOME:-$HOME/.config}" /etc /var/lib/postgres /var/lib/pleroma/static/instance \
|
2021-10-31 19:27:18 +00:00
|
|
|
-maxdepth 4 -follow \( -name Partitions -o -name mdn -o -name .git -o -name .local -o -name plugged \) -prune -o \
|
2021-09-27 09:18:37 +00:00
|
|
|
! -iname "*.markdown" -a ! -iname "*.md" -a ! -iname "*.org" \
|
2021-09-21 21:10:39 +00:00
|
|
|
-type f -readable -exec grep -lI '' {} + 2>/dev/null; } | dedup
|
2021-09-18 21:04:50 +00:00
|
|
|
}
|
2021-09-20 06:56:42 +00:00
|
|
|
|
2021-09-18 21:23:11 +00:00
|
|
|
conf_cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/edconf"
|
2021-09-18 21:04:50 +00:00
|
|
|
conf_cache="$conf_cache_dir/files"
|
|
|
|
conf_tmp="${conf_cache}.tmp"
|
|
|
|
mkdir -p "$conf_cache_dir"
|
|
|
|
touch "$conf_cache"
|
2021-09-20 06:56:42 +00:00
|
|
|
|
2021-10-04 08:46:40 +00:00
|
|
|
sel=$(listconf | fzf -1 -0 --tiebreak=end,length --preview '$(test -r {} || echo "sudo") bat --color=always --style=numbers --line-range :200 {}' --query="$1" --history "$conf_cache_dir/searches")
|
2021-09-18 21:23:11 +00:00
|
|
|
case "$sel" in
|
|
|
|
"") exit 1;;
|
|
|
|
/etc/sudoers) sudo visudo;;
|
|
|
|
/etc/fstab) sudoedit "$sel" && sudo findmnt --verify;;
|
|
|
|
/etc/default/grub) sudoedit "$sel" && sudo grub-mkconfig -o /boot/grub/grub.cfg;;
|
2021-09-20 19:34:00 +00:00
|
|
|
/etc/locale.gen) sudoedit "$sel" && sudo locale-gen;;
|
2021-09-21 20:32:35 +00:00
|
|
|
*) $(test -w "$sel" || echo sudo) "$EDITOR" "$sel";;
|
2021-09-18 21:23:11 +00:00
|
|
|
esac
|
|
|
|
echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache"
|