From f7888ec4604f96928b53bba292cf56c3cf818465 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 22 Dec 2022 15:44:02 +0100 Subject: [PATCH] bin: alias adjustments --- .bash_aliases | 6 +++++ .config/shell/functions | 10 +++++---- .local/bin/scripts/focus | 1 + .local/bin/scripts/mp | 8 +++---- .local/bin/scripts/troubleshoot.sh | 35 ++++++++++++++++++++++++++++++ .local/bin/scripts/twsm | 2 +- 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100755 .local/bin/scripts/troubleshoot.sh diff --git a/.bash_aliases b/.bash_aliases index 21093e7..825f6f3 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -8,9 +8,15 @@ if test -f /etc/bash_completion && ! shopt -oq posix then . /etc/bash_completion fi +alias sc="sudo systemctl" alias scs="sudo systemctl status" +alias sce="sudo systemctl enable --now" alias scr="sudo systemctl reload-or-restart" + +# Diff recursively difr() { diff --color=always --unified=1 --recursive "$@" | less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen; } +# Copy recursively with rsync +alias rc='rsync --recursive --info=progress2,remove,symsafe,flist,del --human-readable --links --hard-links --times' # ls aliases diff --git a/.config/shell/functions b/.config/shell/functions index 5e4edc1..9f56e9d 100644 --- a/.config/shell/functions +++ b/.config/shell/functions @@ -315,7 +315,9 @@ sshl() { local authcache="/var/tmp/ssh-keys" mkdir -p "$authcache" local file="$authcache/$1" - test "$all" && pass scp ~/.bash_aliases "$@:" # TODO also add sourcing to bashrc if needed + test "$all" && + pass scp ~/.bash_aliases "$1:" && + pass ssh "$1" 'grep -q ".bash_aliases" .bashrc || echo "source ~/.bash_aliases" >>.bashrc' if ssh -G "$1" | grep --silent "^user root$" && ! [[ "$1" =~ "pve*" ]] then pass ssh "$@" else @@ -393,7 +395,7 @@ hex() { hexyl "$@" | "${PAGER:-less}"; } export DICT="$XDG_DATA_HOME/dictcc" dic() { result=$(cat $DICT/dict.txt | sed '/#/d;/&/d;/^$/d' | fzf --tiebreak=chunk,length --bind='alt-bspace:clear-query' --print-query --query="$1") && - dic "$(echo "$result" | tail -1 | sed 's/\t/\n/g' | grep --invert-match --ignore-case "$(echo "$result" | head -1)" | head -1 | sed 's/ \W.*//')" + dic "$(echo "$result" | tail -1 | sed 's/\t/\n/g' | head -2 | grep --invert-match --ignore-case "$(echo "$result" | head -1)" || echo "$result" | head -1 | sed 's/ \W.*//')" } #fzf --tiebreak=length --bind='alt-bspace:clear-query' alias dict="rlwrap rdictcc --directory $DICT" @@ -493,14 +495,14 @@ lowercase() { # rsync directory properly - suffix both dirs with / to act on contents alias rcn='rsync -v --recursive --human-readable --links --dry-run' rcd() { rcn --size-only "$@" | tail +2 | tree --fromfile . | less -F; } -alias rc='rcs --links --times' +compdef rcd=rsync +alias rc='rcs --links --hard-links --times' alias rcu='rc --existing --size-only' alias rcs='rsync --recursive --info=progress2,remove,symsafe,flist,del --human-readable' alias dsync='rc --delete --specials' alias move='rc --remove-source-files' alias rdiff='rsync --recursive --progress --delete --links --dry-run' alias rdiffe='rdiff --existing --size-only' -compdef rcd=rsync # Swap the names of two files swap() { diff --git a/.local/bin/scripts/focus b/.local/bin/scripts/focus index f57db9e..3aa3f14 100755 --- a/.local/bin/scripts/focus +++ b/.local/bin/scripts/focus @@ -3,6 +3,7 @@ # depends: mp mpc # env: MUSIC # args: either a playlist file name, or a list of terms which all have to match +# TODO fails on "Alchemy" PLAYLISTS="${PLAYLISTS:-$MUSIC/Playlists}" mpc -q clear if test -z "$1" diff --git a/.local/bin/scripts/mp b/.local/bin/scripts/mp index d97664b..112d462 100755 --- a/.local/bin/scripts/mp +++ b/.local/bin/scripts/mp @@ -6,7 +6,7 @@ # TODO auto-convert unknown types with ffmpeg to flac rather than linking (wav, opus, ...) MPD_CONF=${XDG_CONFIG_HOME:-$HOME/.config}/mpd/mpd.conf MUSIC="${MUSIC:-$(cat $MPD_CONF | grep music_directory | cut -d'"' -f2 | sed "s|~|$HOME|")}" -PLAYLISTS="${$(cat $MPD_CONF | grep playlist_directory | cut -d'"' -f2 | sed "s|~|$HOME|"):-$MUSIC/Playlists}" +PLAYLISTS="$(cat $MPD_CONF | grep playlist_directory | cut -d'"' -f2 | sed "s|~|$HOME|" || echo "$MUSIC/Playlists")" LINKS="$MUSIC/links" if test "$1" = "-r" then shift @@ -14,10 +14,10 @@ then shift # TODO this is sooo slow... for arg do - matchname="$(basename -- "$arg" | sed 's|\(\[.*\)\]|\\\1\\]|;s|\?|\\?|')*" + matchname="$(basename -- "$arg" | sed 's|\(\[.*\)\]|\\\1\\]|;s|\?|\\?|')" filepath="$({ find "$(dirname -- "$arg")" -maxdepth 1 -name "$matchname" -exec realpath {} + || - find "$MUSIC/$(dirname -- "$arg")" "$MUSIC/Playlists/$(dirname -- "$arg")" -maxdepth 1 \ - -name "$matchname" -exec realpath {} +; } 2>/dev/null)" + find "$(dirname -- "$arg")" "$MUSIC/$(dirname -- "$arg")" "$MUSIC/Playlists/$(dirname -- "$arg")" -maxdepth 1 \ + -name "$matchname*" -exec realpath {} +; } 2>/dev/null)" test -n "$verbose" && echo "Scanning path '$filepath' $( test "$arg" != "$filepath" && echo "from '$arg' ")(MUSIC: '$MUSIC', PWD: '$PWD')" >&2 test $(printf "$filepath" | wc -l) -gt 0 && printf "$filepath" | xargs --delim='\n' "$0" -r $verbose && continue diff --git a/.local/bin/scripts/troubleshoot.sh b/.local/bin/scripts/troubleshoot.sh new file mode 100755 index 0000000..cadff7d --- /dev/null +++ b/.local/bin/scripts/troubleshoot.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# Troubleshoot.sh +# A more elaborate version of Troubleshoot.sh. + +SUCCESS=0 +E_DB=99 # Error code for missing entry. + +declare -A address + +date=$(date +%F) +hd_log="/tmp/${date}_HDs.log" + +smartctl --scan | awk '{print $1}' > $hd_log +lspci | grep -i raid >> $hd_log + +getArray () { + i=0 + while read line # Read a line + do + array[i]=$line # Put it into the array + i=$(($i + 1)) + done < $1 +} + +getArray $hd_log + +for e in "${array[@]}" +do + if [[ $e =~ /dev/sd* || $e =~ /dev/hd* ]] + then + echo "smartctl -i -A $e" >> ${date}_Troubleshoot.log + smartctl -i -A $e >> ${date}_Troubleshoot.log # Run smartctl on all disks + fi +done +exit $? # In this case, exit code = 99, since that is function return. diff --git a/.local/bin/scripts/twsm b/.local/bin/scripts/twsm index 6c1eb54..2f54d30 100755 --- a/.local/bin/scripts/twsm +++ b/.local/bin/scripts/twsm @@ -1,4 +1,4 @@ #!/bin/sh # Timewarrior summary of the last n weeks timew summary $(date --date="Monday $1 week ago" -I) to tomorrow :ids ${@:2} | - less --quit-if-one-screen +G + less --quit-if-one-screen