emacs --eval "(ediff-files \"$1\" \"$2\")"
}
+# etail + grep.
+etailg() {
+ _bntmp() {
+ ngset
+ tailf /var/log/exim4/mainlog /var/log/exim4/*main /var/log/exim4/paniclog /var/log/exim4/*panic -n 200 | grp "$@"
+ ngreset
+ }
+ bn _bntmp "$@"
+}
# mail related
# shellcheck disable=SC2120 # we expect to pass arguments in use outside this file
etail() {
pk1 emacs --daemon
}
+# execute, grep & background with bn. usage:
+#
+# CMD GREP ARGS
+# CMD CMD_ARGS - GREP ARGS
+_grx() {
+ local arg
+ local -a cmd grep_args
+ cmd=("$1")
+ shift
+ for arg; do
+ if [[ $arg == "-" ]]; then
+ cmd+=("${grep_args[@]}")
+ grep_args=()
+ else
+ grep_args+=("$arg")
+ fi
+ done
+ "${cmd[@]}" | grp "${grep_args[@]}"
+}
+grx() {
+ bn _grx "$@"
+}
+
+# grep to pipe in interactive shell
+grp() {
+ gr --color=always --line-buffered "$@" || return $?
+}
gr() {
grep -iIP --color=auto "$@" || return $?
}
jr() { journalctl -e -n100000 "$@" ; }
jrf() { SYSTEMD_COLORS=true bn journalctl -n1000 -f "$@" ; }
jrfg() {
- _bntmp() { SYSTEMD_COLORS=true journalctl -n1000 -f | gr --line-buffered "$@"; }
+ _bntmp() { SYSTEMD_COLORS=true journalctl -n1000 -f | grp "$@"; }
bn _bntmp "$@"
}
jru() {
local unit
unit="$1"
shift
- SYSTEMD_COLORS=true journalctl -n1000 -f -u "$unit" | gr --line-buffered "$@"
+ SYSTEMD_COLORS=true journalctl -n1000 -f -u "$unit" | grp "$@"
}
bn _bntmp "$@"
}
# The name bn is not special.
#
# Note: if you want to tail -f | grep, wrap it in a function
-# first, and use grep --line-buffered (because we are piping to a pipe).
+# first, and use grep --line-buffered --color=always (because we are piping to a pipe).
#
# Note: colorization will need to be turned on since it captures
# output to a pipe, eg: SYSTEMD_COLORS=true bn journalctl -f
local line lwlc i
"$@" |& while read -r line; do
# lwlc = line wrapped line count.
- lwlc=$(( ${#line} / COLUMNS + 1 ))
+ # https://stackoverflow.com/questions/17998978/removing-colors-from-output
+ lwlc=$(( $(printf %s "$line" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" | wc -c ||:) / COLUMNS + 1 ))
# from man terminfo
# tput sc = \e7 = save cursor
# tput rc = \e8 = restore cursor
# ssh with multiplexing.
ssm() {
sl -oControlPath=/tmp/ssh_mux_%u_%h_%p_%r "$@"
- }
+}
# ssh solo, without multiplexing. # currently the default, but I might switch back.
sss() {
ssh -oControlPath=none "$@"