mirror of
https://github.com/chenasraf/dotfiles.git
synced 2026-05-17 17:28:07 +00:00
73 lines
1.2 KiB
Bash
73 lines
1.2 KiB
Bash
source $HOME/.dotfiles/colors.sh
|
|
|
|
motd() {
|
|
if [[ -f /etc/motd.head ]]; then lolcat -f /etc/motd.head; fi
|
|
uname -a
|
|
if [[ -f /etc/motd ]]; then cat /etc/motd; fi
|
|
}
|
|
|
|
docker-bash() {
|
|
docker exec -ti $1 /bin/bash
|
|
}
|
|
|
|
# Functions
|
|
|
|
# show all man entries under a specific section
|
|
# e.g. mansect 7
|
|
mansect() { man -aWS ${1?man section not provided} \* | xargs basename | sed "s/\.[^.]*$//" | sort -u; }
|
|
|
|
# TODO not working with custom commands...
|
|
tcd() {
|
|
source $HOME/.zshrc
|
|
cd $1
|
|
shift
|
|
exec $@ 2>&1 | tee --
|
|
# command "$@" 2>&1
|
|
cd $OLDPWD
|
|
}
|
|
|
|
# mkdir -p then navigate to said directory
|
|
mkcd() {
|
|
mkdir -p -- "$1" && cd -P -- "$1"
|
|
}
|
|
|
|
listening() {
|
|
if [[ $# -eq 0 ]]; then
|
|
lsof -iTCP -sTCP:LISTEN -n -P
|
|
elif [[ $# -eq 1 ]]; then
|
|
lsof -iTCP -sTCP:LISTEN -n -P | grep -i --color $1
|
|
else
|
|
echo "Usage: listening [pattern]"
|
|
fi
|
|
}
|
|
|
|
# example echo '1' | prepend 'result: '
|
|
prepend() {
|
|
echo -n "$@"
|
|
cat -
|
|
}
|
|
|
|
lcase() {
|
|
echo "$@" | tr '[:upper:]' '[:lower:]'
|
|
}
|
|
|
|
int_res() {
|
|
# get all but last
|
|
c=$(($# - 1))
|
|
out="$(lcase $(bash -c "${@:1:$c}"))"
|
|
check="$(lcase ${@: -1})"
|
|
if [[ $out =~ $check ]]; then
|
|
echo 0
|
|
else
|
|
echo 1
|
|
fi
|
|
}
|
|
|
|
is_mac() {
|
|
int_res "uname -s" "darwin"
|
|
}
|
|
|
|
is_linux() {
|
|
int_res "uname -s" "linux"
|
|
}
|