config/shell: script adjustments

This commit is contained in:
xeruf 2021-09-21 20:32:35 +00:00
parent bab2d6effc
commit 156ff8784d
8 changed files with 37 additions and 29 deletions

View File

@ -29,7 +29,7 @@ mkcd() {
} }
cd() { cd() {
test "$1" != "-" -a ! -d "$1" -a $# -eq 1 && test -d "$DATA" && test "$1" != "-" -a ! -d "$1" -a $# -eq 1 &&
dir=$(f --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1) && dir=$(f --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1) &&
test -n "$dir" && cd "$dir" && return test -n "$dir" && cd "$dir" && return
builtin cd $1 && builtin cd $1 &&

View File

@ -254,7 +254,9 @@ swap() {
} }
alias f="noglob $(which fd >/dev/null && echo fd || echo fdfind) --hidden --no-ignore-vcs --one-file-system" alias f="noglob fdd"
fdd() { $(which fd >/dev/null && echo fd || echo fdfind) --color=always --hidden --no-ignore-vcs --one-file-system "$@" | less -F; }
compdef f=fd
#alias f='find -not -path "*.sync*" -and -not \( -name daten -prune \)' #alias f='find -not -path "*.sync*" -and -not \( -name daten -prune \)'
#alias f1='find -mindepth 1 -maxdepth 1' #alias f1='find -mindepth 1 -maxdepth 1'

View File

@ -12,7 +12,8 @@ echo "fs.inotify.max_user_watches=800000" | sudo tee /etc/sysctl.d/60-max-user-w
sudo sysctl --system sudo sysctl --system
highlight "Default sudoers configuration" highlight "Default sudoers configuration"
echo "Defaults editor=/usr/bin/nvim" | sudo tee /etc/sudoers.d/editor echo 'Defaults editor=/usr/bin/nvim
Defaults env_keep="EDITOR"' | sudo tee /etc/sudoers.d/editor
echo -e "Defaults timestamp_timeout=120\nDefaults passwd_timeout=30" | sudo tee /etc/sudoers.d/timeout echo -e "Defaults timestamp_timeout=120\nDefaults passwd_timeout=30" | sudo tee /etc/sudoers.d/timeout
highlight "password-free reboot" highlight "password-free reboot"
echo "$USER ALL = NOPASSWD: /sbin/halt, /sbin/reboot, /usr/sbin/reboot, /sbin/poweroff, /usr/sbin/shutdown" | sudo tee /etc/sudoers.d/shutdown echo "$USER ALL = NOPASSWD: /sbin/halt, /sbin/reboot, /usr/sbin/reboot, /sbin/poweroff, /usr/sbin/shutdown" | sudo tee /etc/sudoers.d/shutdown

View File

@ -8,7 +8,7 @@ for last; do true; done
last=${last:-.} last=${last:-.}
# Elevate permissions if the file exists but is not accessible # Elevate permissions if the file exists but is not accessible
test -r "$(dirname $last)" || elevate=sudo test -x "$(dirname $last)" || elevate=sudo
tput setaf 4 && $elevate file -E "$last" | ( grep -v --color=never 'directory$' || true ) tput setaf 4 && $elevate file -E "$last" | ( grep -v --color=never 'directory$' || true )
case "$($elevate file --dereference --mime "$last")" in case "$($elevate file --dereference --mime "$last")" in

View File

@ -1,9 +1,13 @@
#!/bin/sh #!/bin/sh -e
# Checks whether the current user has rights to the respective file, # Checks whether the current user has rights to the respective file(s),
# even if it does not exist. # even if it does not exist.
# First parameter defines which rights are required and is passed to "test". # First parameter defines which rights are required and is passed to "test".
dir="$2" flag=$1
while test $# -gt 1; do
shift
dir="$1"
while ! test -e "$dir" while ! test -e "$dir"
do dir="$(dirname "$dir")" do dir="$(dirname "$dir")"
done done
test $1 "$dir" test $flag "$dir"
done

View File

@ -5,7 +5,7 @@ alias dedup='awk '"'"'!a[$0]++'"'"
listconf() { listconf() {
{ cat "$conf_cache"; { cat "$conf_cache";
fd --hidden --type file --size -1m --max-depth 1 . ~; fd --hidden --type file --size -1m --max-depth 1 . ~;
find "${XDG_CONFIG_HOME:-$HOME/.config}" /etc -maxdepth 3 -follow -type f -readable -exec grep -lI '' {} + 2>/dev/null; } | dedup find "${XDG_CONFIG_HOME:-$HOME/.config}" /etc /var/lib/postgres -maxdepth 4 -follow -type f -readable -exec grep -lI '' {} + 2>/dev/null; } | dedup
} }
conf_cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/edconf" conf_cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/edconf"
@ -21,6 +21,6 @@ case "$sel" in
/etc/fstab) sudoedit "$sel" && sudo findmnt --verify;; /etc/fstab) sudoedit "$sel" && sudo findmnt --verify;;
/etc/default/grub) sudoedit "$sel" && sudo grub-mkconfig -o /boot/grub/grub.cfg;; /etc/default/grub) sudoedit "$sel" && sudo grub-mkconfig -o /boot/grub/grub.cfg;;
/etc/locale.gen) sudoedit "$sel" && sudo locale-gen;; /etc/locale.gen) sudoedit "$sel" && sudo locale-gen;;
*) edit "$sel";; *) $(test -w "$sel" || echo sudo) "$EDITOR" "$sel";;
esac esac
echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache" echo "$sel" | cat - "$conf_cache" | head -20 >"$conf_tmp" && mv "$conf_tmp" "$conf_cache"

View File

@ -1,2 +1,3 @@
#!/bin/sh #!/bin/sh
git rev-parse @{upstream} >/dev/null 2>&1 || git branch --set-upstream-to=@{push}
git pull --rebase --autostash "$@" || (printf "\e[31;1mError - aborting rebase!\e[0m\n" >&2 && git rebase --abort) git pull --rebase --autostash "$@" || (printf "\e[31;1mError - aborting rebase!\e[0m\n" >&2 && git rebase --abort)

View File

@ -4,6 +4,6 @@
# Automatically elevates if missing permissions. # Automatically elevates if missing permissions.
for last; do true; done for last; do true; done
! test -e "$1" && echo "$1 does not exist" && exit 1 ! test -e "$1" && echo "$1 does not exist" && exit 1
checkaccess -w "$last" || elevate=sudo checkaccess -w "$@" || elevate=sudo
$elevate mkdir -p $(case "$last" in (*/) echo "$last";; (*) dirname "$last";; esac) $elevate mkdir -p $(case "$last" in (*/) echo "$last";; (*) dirname "$last";; esac)
$elevate mv -n "$@" $elevate mv -n "$@"