ta /var/log/exim4/mainlog /var/log/exim4/*main /var/log/exim4/paniclog /var/log/exim4/*panic -n 200 "$@"
ngreset
}
-
+# shellcheck disable=SC2120
etail() {
tail -F /var/log/exim4/mainlog /var/log/exim4/*main /var/log/exim4/paniclog /var/log/exim4/*panic -n 200 "$@"
}
done
}
-
-k() { # history search
- grep -iP --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | tail -n 80 || [[ $? == 1 ]];
+# history search
+k() {
+ local grep_out1 grep_out2 histf1 histf2
+ local -a lines1 lines2
+ histf1=${HISTFILE:-~/.bash_history}
+ grep_out1=$(grep -iP --binary-files=text "$@" $histf1 | tail -n 80) || [[ $? == 1 ]]
+ if [[ $EUID == 0 ]]; then
+ histf2="/home/iank/${histf1##*/}"
+ grep_out2=$(grep -iP --binary-files=text "$@" $histf2 | tail -n 80) || [[ $? == 1 ]]
+ elif sudo -nv 2>/dev/null; then
+ histf2="/root/${histf1##*/}"
+ grep_out2=$(sudo grep -iP --binary-files=text "$@" $histf2 | tail -n 80) || [[ $? == 1 ]]
+ fi
+ if [[ $grep_out1 && $grep_out2 ]]; then
+ mapfile -t lines1 <<<"$grep_out1"
+ mapfile -t lines2 <<<"$grep_out2"
+ # in this case, just insert a chunk of secondary results in the middle.
+ if (( ${#lines1[@]} > 20 )); then
+ printf "%s\n" "${lines1[@]:20}"; printf "############ ^ %s #############\n" $histf1
+ printf "%s\n" "${lines2[@]::20}"; printf "############ ^ %s #############\n" $histf2
+ printf "%s\n" "${lines1[@]::20}"
+ else
+ printf "%s\n" "${lines2[@]}"; printf "########## ^ %s #########\n" $histf2;
+ printf "%s\n" "${lines1[@]}"
+ fi
+ elif [[ $grep_out2 ]]; then
+ printf "%s\n" "${lines2[@]}"; printf "### ^ %s\n" $histf2
+ elif [[ $grep_out1 ]]; then
+ printf "%s\n" "${lines1[@]}"
+ fi
}
+
ks() { # history search with context
# args are an extended regex used by sed
history | sed -nr "h;s/^\s*(\S+\s+){4}//;/$*/{g;p}" | tail -n 80 || [[ $? == 1 ]];