dotfiles/bashrc/worthwhile-functions

55 lines
1.8 KiB
Bash

#!/bin/bash
# shellcheck disable=SC2199,SC2068,SC1091,SC2086,SC2145
# custom function management here
# changes to the worthwhile-functions filepath requires
# an update o the filepath via 'edit-script reload-funcs-bashrc
# and also any reference here
disable-funcs () {
echo "info: Unimplemented yet. Tell Andrei to add it to his todo."
}
edit-funcs-bashrc() {
$(echo $EDITOR || command -v nano>>/dev/null && echo nano || echo vi) ~/.dotfiles/bashrc/worthwhile-functions
}
list-debs-size() {
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rn | less
}
edit-script-file() {
# if you use other editor, please set $EDITOR.
$(echo $EDITOR || command -v code>>/dev/null && echo code || command -v nano>>/dev/null && echo nano || echo vi) "$(command -v $1)"
}
# reloading stuff
refresh-funcs() {
"$DOTFILES_STUFF_BIN/reload-funcs-bashrc"
}
refresh-aliases() {
source "$HOME/.dotfiles/bashrc/aliases"
}
# https://commentedcode.org/blog/2020/09/21/changing-default-branch-of-git-init/
git() {
# check command for some automation KEK, especially i want to do DCO by default
if [[ "$1" == "init" && "$@" != *"--help"* ]]; then
[[ $DEBUG != "" ]] && echo "args: $@" && sleep 3
if command git "$@"; then
echo "Setting HEAD to branch main"
command git symbolic-ref HEAD refs/heads/main
fi
elif [[ "$1" == "commit" && "$@" != *"--help"* && ( "$@" != *"--signoff"* && "$@" != *"-s"* && $@ != *"--amend" ) ]]; then
[ $DEBUG != "" ] && echo "args: $@ --signoff" && sleep 3
command git "$@" --signoff
elif [[ "$1" == "pull" && "$@" != *"--help"* && ( "$@" != *"--signoff"* && "$@" != *"-s"* ) ]]; then
command git "$@" --signoff
else
command git "$@"
fi
}
list-nodejs-scripts() {
[[ -f "package.json" ]] && jq .scripts < package.json || echo "No package.json found in current directory."
}