bin: expand edconf responsibilities

This commit is contained in:
xeruf 2021-09-18 23:23:11 +02:00
parent 09e73b1b1f
commit b6ebff6655
2 changed files with 12 additions and 9 deletions

View File

@ -41,17 +41,13 @@ wh() {
res=$(which "$@")
if expr "$res" : "${@:$#}: aliased to" >/dev/null && ! expr "$res" : ".*builtin" >/dev/null
then echo "$res" | bat --style=plain --language=sh &&
wh $(expr "$res" : "${@:$#}: aliased to ${@:$#} " >/dev/null && echo "-p") $(echo "$res" | cut -d' ' -f$(expr 5 '&' "$res" : ".*\(sudo\|noglob\)" '|' 4) | cut -d'(' -f2)
wh $(expr "$res" : "${@:$#}: aliased to ${@:$#} " >/dev/null && echo "-p") $(echo "$res" | cut -d' ' -f$(expr 5 '&' "$res" : ".*to \(sudo\|noglob\) " '|' 4) | cut -d'(' -f2)
# use command which for other shells
else test -r "$res" && b --style=header "$res" || echo "$res" | bat --style=plain --language=sh
fi
}
compdef wh=which
# Some configuration aliases that include sane verification
alias edgrub='sudoedit /etc/default/grub && sudo update-grub'
alias edpart='sudoedit /etc/fstab && sudo findmnt --verify'
alias edenv='sudoedit /etc/environment'
pathadd() {
local IFS=":"
local result="$@"

View File

@ -4,13 +4,20 @@ alias dedup='awk '"'"'!a[$0]++'"'"
listconf() {
{ cat "$conf_cache"; test -f "$conf_extra" && cat "$conf_extra";
fd --hidden --type file --size -1m --max-depth 1 . ~;
find "$XDG_CONFIG_HOME" /etc -maxdepth 3 -type f -readable -exec grep -lI '' {} + 2>/dev/null; } | dedup
find "${XDG_CONFIG_HOME:-$HOME/.config}" /etc -maxdepth 3 -type f -readable -exec grep -lI '' {} + 2>/dev/null; } | dedup
}
conf_cache_dir="$XDG_CACHE_HOME/edconf"
conf_cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/edconf"
conf_cache="$conf_cache_dir/files"
conf_tmp="${conf_cache}.tmp"
conf_extra="$XDG_CONFIG_HOME/edconf-extra"
conf_extra="${XDG_CONFIG_HOME:-$HOME/.config}/edconf-extra"
mkdir -p "$conf_cache_dir"
touch "$conf_cache"
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")
test "$sel" && ((echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache") & edit "$sel")
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;;
*) edit "$sel";;
esac
echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache"