initial commit
This commit is contained in:
61
bash/.functions
Normal file
61
bash/.functions
Normal file
@@ -0,0 +1,61 @@
|
||||
# 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 Git’s 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
|
||||
}
|
||||
Reference in New Issue
Block a user