# SPDX-License-Identifier: AGPL-3.0-or-later
# this gets sourced. shebang is just for file mode detection
-
# Use source ~/.bashrc instead of doing bash -l when running a script
# so this can set extdebug and avoid the bash debugger.
if [[ -s /a/bin/errhandle/err ]]; then
rm ~/.bash_logout
fi
+# if [[ -s /usr/share/bash-completion/completions/git ]]; then
+# source /usr/share/bash-completion/completions/git
+# fi
+# if [[ -s /usr/share/bash-completion/completions/gitk ]]; then
+# source /usr/share/bash-completion/completions/gitk
+# fi
+
# for testing error catching:
# t2() {
# echo t2
CDPATH=.
+
# remove all aliases. aliases provided by the system tend to get in the way,
# for example, error happens if I try to define a function the same name as an alias
unalias -a
fi
+
+
# * functions
+# when testing for completions, uncomment this
+# cm() { _completion_loader $1 &>/dev/null ||:; complete -p $1; }
+ccomp() {
+ local src=$1
+ shift
+ _completion_loader $src &>/dev/null ||:
+ complete -p $src &>/dev/null || return 0
+ eval $(complete -p $src | sed -r "s/ $src($| )/ $*\1/")
+}
+
..() { c ..; }
...() { c ../..; }
echo -n "$x" | xclip
}
-ack() { ack-grep "$@"; }
-
b() {
# backwards
c -
else
c() { cd "$@"; }
fi
+ccomp cd c
c4() { c /var/log/exim4; }
-exec bash -c '. ~/.bashrc; hr; echo "$1"; hr; cat "$1"' _ {} \; 2>/dev/null
}
+ccomp cat cf caf
calc() { echo "scale=3; $*" | bc -l; }
# no having to type quotes, but also no command history:
git commit -am "$*"
}
-
ccat () { # config cat. see a config without extra lines.
grep '^\s*[^;[:space:]#]' "$@" || [[ $? == 1 ]]
}
+ccomp grep ccat
chrbind() {
local d
c =
}
-d() { builtin bg; }
-complete -A stopped -P '"%' -S '"' d
-
+d() { builtin bg "$@"; }
+ccomp bg d
dc() {
diff --strip-trailing-cr -w "$@" # diff content
}
+ccomp diff dc
despace() {
local x y
fi
done
}
+ccomp dig digsort
# compare digs to the 2 servers
# usage: digdiff @server1 @server2 DIG_ARGS
# note: only the soa master nameserver will respond with
dt() {
date "+%A, %B %d, %r" "$@"
}
+ccomp date dt
dus() { # du, sorted, default arg of
du -sh ${@:-*} | sort -h
}
-
+ccomp du dus
e() { echo "$@"; }
etail() {
tail -F /var/log/exim4/mainlog -n 200 "$@"
}
+ccomp tail etail
# print exim old pids
eoldpids() {
eless() {
less /var/log/exim4/mainlog
}
+ccomp less eless
eqcat() {
exiqgrep -i | while read -r i; do
m exim -Mvh $i
}
faf() { # find all files. use -L to follow symlinks
- find $@ -not \( -name .svn -prune -o -name .git -prune \
+ find "$@" -not \( -name .svn -prune -o -name .git -prune \
-o -name .hg -prune -o -name .editor-backups -prune \
-o -name .undo-tree-history -prune \) -type f 2>/dev/null
}
fi
}
-# force terminal verion
+# force terminal version
gn() {
g -n "$@"
}
gr() {
grep -iIP --color=auto "$@" || return $?
}
-
grr() { # grep recursive
# Don't return 1 on nonmatch because this is meant to be
# interactive, not in a conditional.
grep --exclude-dir='*.emacs.d' --exclude-dir='*.git' -riIP --color=auto "$@" || [[ $? == 1 ]]
fi
}
+ccomp grep gr grr
+
rg() {
command rg -i -M 200 "$@"
}
}
i() { git "$@"; }
-# modified from ~/local/bin/git-completion.bash
-# other completion commands are mostly taken from bash_completion package
-complete -o bashdefault -o default -o nospace -F _git i 2>/dev/null \
- || complete -o default -o nospace -F _git i
-
-if ! type service &>/dev/null; then
- service() {
- echo actually running: systemctl $2 $1
- systemctl $2 $1
- }
-fi
-
-
+ccomp git i
ic() {
# fast commit all
}
-
ifn() {
# insensitive find
find -L . -not \( -name .svn -prune -o -name .git -prune \
fi
}
-
lcn() { locate -i "*$**"; }
-lg() { LC_COLLATE=C.UTF-8 ll --group-directories-first; }
+lg() { LC_COLLATE=C.UTF-8 ll --group-directories-first "$@"; }
lt() { ll -tr "$@"; }
lld() { ll -d "$@"; }
+ccomp ls l lg lt lld ll
+
+
low() { # make filenames lowercase, remove bad chars
local f new
for f in "$@"; do
k() { # history search
grep -iP --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | tail -n 80 || [[ $? == 1 ]];
}
-
ks() { # history search
grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history} | uniq || [[ $? == 1 ]];
}
+ccomp grep k ks
make-targets() {
mkdir "$1"
c "$1"
}
+ccomp mkdir mkc
mkct() {
mkc $(mktemp -d)
rl() {
readlink -f "$@"
}
+ccomp readlink rl
rsd() {
# rsync, root is required to keep permissions right.
# do not exist on the original end.
rsync -ahvic "$@"
}
-complete -F _rsync -o nospace rld rl rlt
-
rst() {
# rl without preserving modification time.
rsync -ahvic --delete --no-t "$@"
}
-
rsu() { # [OPTS] HOST PATH
# eg. rlu -opts frodo /testpath
# relative paths will expanded with readlink -f.
# to keep up with unison.
sudo rsync -rlpchviog --relative "${opts[@]}" "$path" "root@$host:/";
}
+ccomp rsync rsd rsa rst rsu
+
rmstrips() {
ssh fencepost head -n 300 /gd/gnuorg/EventAndTravelInfo/rms-current-trips.txt | less
"$@"
fi
}
+ccomp sudo s
safe_rename() { # warn and dont rename if file exists.
# mv -n exists, but it\'s silent
m ssh -O exit "$@" || [[ $? == 255 ]]
m sl "$@"
}
+ccomp ssh sl slr sss ssk
# plain ssh
ssh() {
LC_USEBASHRC=t command ssh "$@"
local f=/home/iank/.emacs.d/init.el
sl --sl-test-cmd ". /etc/os-release ; printf %s \${VERSION//[^a-zA-Z0-9]/}; test -e $f && stat -c%Y $f" --sl-test-hook slemacs "$@"
}
+ccomp ssh sle
# Run this manually after .emacs.d changes. Otherwise, to check if
# files changed with find takes 90ms. sl normally only adds 25ms. We
/a/f/gnulib/build-aux/gnupload "$@"
}
-# todo, update this
-complete -F _longopt la lower low rlt rld rl lld ts ll dircp ex fcp fct fpst gr
-
abrowserrmcompat() {
local f
ngset
fi
}
-
-
fn() {
firefox -P alt "$@" >/dev/null 2>&1
}
fi
# another alternative is run-mailcap
}
+ccomp xdg-open o
jfilter() {
grep -Evi -e "^(\S+\s+){4}(sudo|sshd|cron)\[\S*:" \
}
jr() { journalctl "$@" | jfilter | less ; }
jrf() { journalctl -n 200 -f "$@" | jfilter; }
-
+ccomp journalctl jtail jr jrf
kff() { # keyboardio firmware flash
pushd /a/bin/distro-setup/Arduino/Model01-Firmware
fi
-# best practice
-unset IFS
# for mitmproxy to get a newer python.
# fi
+# best practice
+unset IFS
+
# https://wiki.archlinux.org/index.php/Xinitrc#Autostart_X_at_login
# i added an extra condition as gentoo xorg guide says depending on
# $DISPLAY is fragile.