Files
dotfiles/bash/.functions
2026-04-06 19:41:06 -06:00

62 lines
1.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Bash Functions
mkcd()
{
mkdir -p -- "$1" && cd -P -- "$1"
}
# determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
# use Gits colored diff when available
hash git &>/dev/null;
if [ $? -eq 0 ]; then
function diff() {
git diff --no-index --color-words "$@";
}
fi;
## system administration
### service files
sysedit() {
local svc="$1"
sudo systemctl edit --full "$svc"
read -p "Reload + restart $svc? [y/N]: " ans
if [[ "$ans" == "y" ]]; then
sudo systemctl daemon-reload
sudo systemctl restart "$svc"
fi
}
sysadd() {
local svc="$1"
sudo systemctl edit "$svc"
read -p "Reload + restart $svc? [y/N]: " ans
if [[ "$ans" == "y" ]]; then
sudo systemctl daemon-reload
sudo systemctl restart "$svc"
fi
}
## bash script helpers
is_true() {
case "${1,,}" in
1|true|yes|y|on) return 0 ;;
*) return 1 ;;
esac
}