Skip to content

Instantly share code, notes, and snippets.

@GiovanniFrigo
Last active May 15, 2018 14:26
Show Gist options
  • Save GiovanniFrigo/a97b430dba60762d9b01 to your computer and use it in GitHub Desktop.
Save GiovanniFrigo/a97b430dba60762d9b01 to your computer and use it in GitHub Desktop.
My own .profile file
####
# Run source ~/.profile to make changes in this file effective
####
# alias ll, if not already present
alias ll='ls -lah'
# I like this colour schema for `ls`
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
# cd into a dir and ls it
cdl_funct()
{
cd $1 && ls
}
alias cdl=cdl_funct
# I do like nano
export EDITOR=nano
# recursive ls function
ls_rec_funct()
{
ls -R | awk '/:$/&&f{s=$0;f=0}/:$/&&!f{sub(/:$/,"");s=$0;f=1;next}NF&&f{ print s"/"$0 }'
}
alias ls-rec=ls_rec_funct
# Alias 'chrome' to start Chrome
alias chrome="open -a Google\ Chrome"
# and 'firefox' to start Firefox
alias firefox="open -a Firefox"
# 'code' opens up Visual Studio Code
alias code="open -a Visual\ Studio\ Code"
# Add a custom `bell` command, useful to notify me on completed tasks:
# `npm run debug && bell`
alias bell="afplay /System/Library/Sounds/Glass.aiff"
# bounce terminal icon. Still for completed tasks:
# `npm install && bounce`
alias bounce="echo -e '\a'"
# some custom parameters for `sdiff` (side by side diff command)
function sidediff {
# get terminal width
cols=`tput cols`;
# save some space for `cat -n`
cols=cols - 8;
sdiff -w $cols -l $1 $2 | cat -n
}
# calculate the fingerprint of an ssh key
alias ssh-fingerprint='ssh-keygen -E md5 -lf'
# adding routes for the Belka VPN
function routeVPN {
sudo route add -host 10.0.0.2/32 -interface ppp0
sudo route add -host 10.0.0.3/32 -interface ppp0
sudo route add -host 10.0.0.4/32 -interface ppp0
}
# List the digital ocean droplets from ~/.servers/do_droplets file
alias list-droplets='sort ~/.servers/do_droplets | (echo "DROPLET_NAME IP FLOATING_IP" && cat) | column -t'
# how it works:
# sort sorts the content of the file aplhabetically
# (echo "Header" && cat) prepends 'Header' to the stdout
# column nicely formats the output into columns (using whitespace as separator)
# Connect to a digital ocean droplet, taking care of passing along the correct identity file
# Can be called passing both an ip address or a droplet name
# If a droplet name is passed in (a string that doesn't look like an IP address), attempts to resolve the droplet name into its IP address
function do-connect {
if [[ -z $1 ]]; then
echo 'Usage: do-connect [IP address/droplet name]'
return
fi
if [[ $1 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
# looks like an IP address, try to connect using it
IP_ADDR=$1
else
# lookup in our droplets list if we have a matching name
FOUND_DROPLET=`grep -i $1 ~/.servers/do_droplets`
if [[ -z $FOUND_DROPLET ]]; then
echo "Couldn't resolve droplet name \"$1\" to an IP address"
return
fi
DROPLET_NAME=`echo $FOUND_DROPLET | awk '{print $1}'`
IP_ADDR=`echo $FOUND_DROPLET | awk '{print $2}'`
echo "Connecting to droplet \"$DROPLET_NAME\".."
fi
echo 'Running `ssh -i ~/.ssh/digitalocean root@'$IP_ADDR'`'
ssh -i ~/.ssh/digitalocean root@$IP_ADDR
}
####
# Legacy stuff
####
# Alias connectdev to ssh into the EM2 development machine
# alias connectdev='sshpass -p ''b3lk4b4us3tt3t3'' ssh [email protected] -p 52325'
# #EM2 GENERAL CONNECT
# function connectem2 {
# if [ -n "$2" ]; then
# pass=$2
# else
# pass='4g4v4zz1pwd'
# fi
# sshpass -p ''$pass'' ssh -o PreferredAuthentications=password utente@$1 -p 52325
# }
# # Control the EM3 dev VM from the command line
# alias vbstartdev='VBoxManage startvm EM3-dev --type headless';
# alias vbstopdev='VBoxManage controlvm EM3-dev acpipowerbutton';
# alias vbrunning='VBoxManage list runningvms';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment