# so this can set extdebug and avoid the bash debugger.
-if [[ -s /a/bin/errhandle/err ]]; then
- # shellcheck source=/a/bin/errhandle/err
- source /a/bin/errhandle/err
+if [[ -s /a/bin/bash-bear-trap/bash-bear ]]; then
+ # shellcheck source=/a/bin/bash-bear-trap/bash-bear
+ source /a/bin/bash-bear-trap/bash-bear
# wtf, shellcheck doesn't allow disabling warnings in elifs
else
# bleh shellcheck can't handle disabling in an elif, so nesting this if.
# shellcheck disable=SC2154 # set in .bashrc
- if [[ -s $bashrc_dir/err ]]; then
- # shellcheck source=/a/bin/errhandle/err
- source $bashrc_dir/err
+ if [[ -s $bashrc_dir/bash-bear ]]; then
+ # shellcheck source=/a/bin/bash-bear-trap/bash-bear
+ source $bashrc_dir/bash-bear
fi
fi
export SL_INFO_DIR=/p/sshinfo
+### begin pyenv ###
+
+# this is adapted from things printed to term after install
+# pyenv. commented for now since I'm not actually using pyenv.
+
+# export PYENV_ROOT="$HOME/.pyenv"
+# command -v pyenv &>/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
+# command -v pyenv &>/dev/null && eval "$(pyenv init -)"
+
+
+# output showed this example for pyenv-virtualenv, which i have no idea
+# what it is, but leaving it as a comment in case I end up doing python
+# dev.
+
+#eval "$(pyenv virtualenv-init -)"
+### end begin pyenv ###
+
+
# * include files
# bash: /usr/share/bashdb/bashdb-main.inc: No such file or directory
# bash: warning: cannot start debugger; debugging mode disabled
if [[ $SOE ]]; then
- if [[ -e /a/bin/errhandle/err ]]; then
- source /a/bin/errhandle/err
+ if [[ -e /a/bin/bash-bear-trap/bash-bear ]]; then
+ source /a/bin/bash-bear-trap/bash-bear
fi
fi
fi
done
}
-## BEGIN functions to change directory better than cd ##
+# like running cl <enter> a <enter>
+cla() {
+ local line
+ mapfile -t lines <~/.cdirs
+ start=$(( ${#lines[@]} - 1 ))
+ for (( j=start; j >= 0; j-- )); do
+ line="${lines[$j]}"
+ if [[ ! $line || ! -d "$line" || $line == "$PWD" || line == "$HOME" ]]; then
+ continue
+ fi
+ e "$line"
+ c "$line"
+ break
+ done
+}
+## END functions to change directory better than cd ##
# pee do. run args as a command with output copied to syslog.
#
ssh-copy-id $1
}
-# ya, hacky hardcoded hostnames in 2023. we could do better
-hssh-update() {
- local -a failed_hosts hosts
- case $HOSTNAME in
- sy|kd)
- hosts=(
- kd x3.office.fsf.org syw
- )
- ;;
- x3)
- hosts=(
- b8.nz sywg.b8.nz
- )
- ;;
- esac
- for host in ${hosts[@]}; do
- e $host
- if ! scp /b/fai/fai/config/files/usr/local/bin/hssh/IANK root@$host:/usr/local/bin/hssh; then
- failed_hosts+=($host)
- fi
- done
- if (( ${#failed_hosts[@]} >= 1 )); then
- echo failed_hosts=${failed_hosts[*]}
- return 1
- fi
-}
-
+# copy path into clipboard
a() {
local x
x=$(readlink -nf "${1:-$PWD}")
done
}
caf() {
- # shellcheck disable=SC2033
+
+ local file
find -L "$@" -type f -not \( -name .svn -prune -o -name .git -prune \
-o -name .hg -prune -o -name .editor-backups -prune \
- -o -name .undo-tree-history -prune \) \
- -exec bash -c '. ~/.bashrc; hr; echo "$1"; hr; cat "$1"' _ {} \; 2>/dev/null
-
+ -o -name .undo-tree-history -prune \) -printf '%h\0%d\0%p\n' | sort -t '\0' -n \
+ | awk -F '\0' '{print $3}' 2>/dev/null | while read -r file; do
+ hr
+ printf "%s\n" "$file"
+ hr
+ cat "$file"
+ done
}
ccomp cat cf caf
echo "scale=3; $x" | bc -l
}
+cx() {
+ chmod +X "$@"
+}
+
cam() {
git commit -am "$*"
}
g() {
- # todo: patch emacs so it will look elsewhere. this is kinda sad:
- # https://emacs.stackexchange.com/questions/4253/how-to-start-emacs-with-a-custom-user-emacs-directory
-
local args gdb=false
if [[ $EMACSDIR ]]; then
fi
fi
if [[ $EMACSDIR ]]; then
+
+ # todo: we don't have to alter HOME since emacs 29+, we can set
+ # user-emacs-directory with the flag --init-directory
+
# Alter the path here, otherwise the nfs mount gets triggered on the
# first path lookup when emacs is not being used.
# shellcheck disable=SC2098 disable=SC2097 # false positive
fi
}
+# g pipe. like: cmd | emacs. save cmd output to tmp file, then edit.
+gp() {
+ cat &>/a/tmp/gtmp
+ g "$@" /a/tmp/gtmp
+}
+# g log
+#like cmd &> tempfile; emacs tempfile
+#
+# note: a useful workflow for doing mass replace on my files:
+# gc rem REGEX
+## remove any false positives, or manually edit them. rename files if needed.
+# sedi 's/REGEX/REPLACEMENT/' $(gr '^/' /a/tmp/gtmp)
+gl() {
+ "$@" &> /a/tmp/gtmp
+ g /a/tmp/gtmp
+}
+# g command substitution
+gc() {
+ g $("$@")
+}
+
# force terminal version
gn() {
g -n "$@"
sed -i --follow-symlinks "$@"
}
+
+
rmstrips() {
ssh fencepost head -n 300 /gd/gnuorg/EventAndTravelInfo/rms-current-trips.txt | less
}
skgit() {
local f
for f in $(i s | awk '$1 == "modified:" {print $2}'); do
- if [[ $(head -n1 "$f") == '#!/bin/bash'* ]]; then
+ if istext "$f" && [[ $(head -n1 "$f" 2>/dev/null) == '#!/bin/bash'* ]]; then
sk $f ||:
fi
done
# on-battery
on-bat() {
if [[ -e /sys/class/power_supply/AC/online && $(</sys/class/power_supply/AC/online) == 0 ]]; then
+ return 0
+ else
return 1
fi
}
# ls count. usage: pass a directory, get the number of files.
# https://unix.stackexchange.com/questions/90106/whats-the-most-resource-efficient-way-to-count-how-many-files-are-in-a-director
lsc() {
+ # shellcheck disable=SC2790 disable=SC2012 # intentional
ls -Uq "$@"|wc -l
}
# run then notify. close notification after the next prompt.
rn() {
"$@"
- dunstify -u critical "$*"
+ dunstify -u critical -h string:x-dunst-stack-tag:profanity "$*"
_psrun=(dunstctl close-all)
}
n() {
- dunstify -u critical n
+ dunstify -u critical -h string:x-dunst-stack-tag:profanity n
_psrun=(dunstctl close-all)
}
}
+disk-info() {
+ local cmds cmd
+ mapfile -t cmds <<'EOF'
+tail -n +1 /proc/mdstat /etc/mdadm/mdadm.conf /etc/fstab /etc/crypttab
+lsblk
+blkid
+ls -la /dev/disk/by-id
+EOF
+
+ for cmd in "${cmds[@]}"; do
+ cat <<EOF
+### $cmd
+
+\`\`\`
+EOF
+ $cmd
+ cat <<'EOF'
+
+```
+
+EOF
+ done
+}
+
# * misc stuff
if $use_color && type -p tput &>/dev/null; then
+ # this is nice for a dark background terminal:
+ # https://github.com/trapd00r/LS_COLORS
+ # I would like if there was something similar for light.
+
+ # the default bold green is too light.
+ # this explains the codes: https://gist.github.com/thomd/7667642
+ export LS_COLORS=ex=1
+
term_bold="$(tput bold)"
term_red="$(tput setaf 1)"
term_green="$(tput setaf 2)"
# we happen to be using that terminal, we can just keep working by
# entering our next command, even a noop in order to dismiss the
# notification, instead of having to explicitly dismiss it.
- if [[ ${_psrun[@]} ]]; then
+ if [[ ${_psrun[*]} ]]; then
if (( _psrun_count >= 1 )); then
"${_psrun[@]}" ||: