- Create a file like
$HOME/.functions - Add all functions you desire
- In your shell conf file add :
if [ -f $HOME/.functions ]; then
. $HOME/.functions
fiSome aliases
# standard conf
alias me="echo $USER"
alias WORKSPACE="cd ~/workspace"
# git alias
alias gt="git tree"
alias gs="git status"
alias gf="git fetch"
alias gu="git update"
alias gb="git branch"
alias gsw="git swich"Change directory
function changeDirectory {
cd $1; ls -la
}
alias lcd=changeDirectoryClean all snapshot from a secific date, by default 1 day cleanSnapshot <date?>
function cleadOldPackage {
DATE=${1:-1}
find $HOME -type f -mtime +$DATE -iname "*SNAPSHOT*" -exec rm -fr {} \;
}
Clean all docker images
function clean_docker {
docker rm -f $(docker ps -a -q)
docker rm -v $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null
docker rmi -f $(docker images -q)
docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null
docker image prune -a -f
docker system prune -a
docker volume prune
}Extract archive
function extract {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}Get file encoding
function fileEncoding {
if [[ -f $1 ]]; then
file -Ib $1
else
echo "'$1' is not a file"
fi
}Create a local ftp on mac
stop_local_ftp() {
sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist
}
start_local_ftp() {
sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist
}Clean all shell history
fucntion cleanHistory {
history -c
history -w
if [ -e "$HOME/.bash_history" ]; then
cat /dev/null > $HOME/.bash_history && history -c
fi
if [ -e "$HOME/.zsh_history" ]; then
cat /dev/null > $HOME/.zsh_history && history -c
fi
exit
}Http server with python
python -m SimpleHTTPServerChange all file extension
function usage {
echo 'usage "rename $1 $2"'
exit 1
}
[[ $# -ne 2 ]] && usage
for i in *.$1; do mv "$i" "`basename $i .$1`.$2"; doneFind in current folder
function search {
if [ "$#" -ne 1 ]; then
echo "usage : search <param>"
else
find . -iname "*$1*"
fi
}Grep on running process
function process {
ps aux | grep $1
}Show open port
sudo lsof -iTCP -sTCP:LISTEN -P -nUpdate auto all outdated libraries on mac
brew update && brew upgrade `brew outdated`Get uptime
uptime | awk '{ print "Uptime:", $3, $4, $5 }' | sed 's/,//g'Watch on cmd
watch -d -n 1 $1List metadata from file
mdls <file>Edit picture metadata
xattr -w com.apple.metadata:<datatype> <data> <file>
#Ex
xattr -w com.apple.metadata:kMDItemWhereFroms <data> <file>Time to first byte
curl -w "Connect time: %{time_connect} Time to first byte: %{time_starttransfer} Total time: %{time_total}" <OPTION> <URL>Get CPU use by process
ps -lf -o "tid,%cpu"Get my ip
function my_ip {
ifconfig | grep "inet " | grep -v 127.0.0.1 | awk '{print $2}'
}