Skip to content

Instantly share code, notes, and snippets.

@psifertex
Created April 22, 2020 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psifertex/685b8c517706b40770a78f5044429d04 to your computer and use it in GitHub Desktop.
Save psifertex/685b8c517706b40770a78f5044429d04 to your computer and use it in GitHub Desktop.
random bash aliases
if which dig >/dev/null 2>/dev/null
then
alias remoteip="dig +short myip.opendns.com @resolver1.opendns.com"
elif which curl >/dev/null 2>/dev/null
then
alias remoteip="curl http://ipecho.net/plain"
fi
function localip()
{
case "$OSTYPE" in
linux*)
#(ip -4 -o addr show eth0|awk '{print $4}'|sed s'/\/..//g'|grep [1-9] || ip -4 -o addr show eth1|awk '{print $4}'|sed s'/\/..//g'|grep [1-9] )|cat
hostname -I
;;
darwin*)
ipconfig getifaddr en1 || ipconfig getifaddr en0 || ipconfig getifaddr en2 || ipconfig getifaddr en3 || ipconfig getifaddr en4 || ipconfig getifaddr en5
;;
esac
}
alias colors='for ((x=0; x<=255; x++));do echo -e "${x}:\033[48;5;${x}mbackground\033[000m\t\033[38;5;${x}mforeground\033[000m";done'
alias allips="ifconfig -a|perl -nle '/(\d+\.\d+\.\d+\.\d+)/ && print \$1'"
function mkcd() { mkdir "$1" && cd "$1"; }
function :wq()
{
kill -9 $$
}
function alert()
{
case "$OSTYPE" in
linux*)
if [ -n "$SSH_CLIENT" ]
then
echo -e "Shell Alert: \a\n$1"
else
if [ -n "$DISPLAY" ]
then
zenity --title 'Alert' --text "$1" --warning
else
echo -e "Shell Alert: \a\n$1"
fi
fi
;;
darwin*)
if [ -n "$SSH_CLIENT" ]
then
echo -e "Shell Alert: \a\n$1"
else
say "$1"
fi
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment