bin: alias adjustments

This commit is contained in:
xeruf 2022-12-22 15:44:02 +01:00
parent b3989a1969
commit f7888ec460
6 changed files with 53 additions and 9 deletions

View File

@ -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

View File

@ -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() {

View File

@ -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"

View File

@ -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

View File

@ -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.

View File

@ -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