I'll start with mine, taken from a tweet from either Taylor Otwell or Jeffrey Way
alias nah="git reset --hard;git clean -df;"
Removes all unstaged files, extremely handy to revert back to a clean state.
(removes all files not checked in -- be careful)
Be careful of running this, as it will clobber anything that's not checked in :)
I am a bit lazy sometimes and for git add + git commit + git push & to know what files have been changed I made a little snippet in my .zshrc file :
# git add + commit + push
function lazygit() {
git add -A
git commit -am "$1"
git push
git show --name-status | cat
}
You still have to pull before to be sure you won't have problems with merge conflicts, if you don't care, you could add a line before push with git pull .
That's not very pretty but it works ;)
I like this one.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\[\033[00m\]\u@\h\[\033[01;33m\] \w \[\033[31m\]\$(parse_git_branch)\[\033[00m\]$\[\033[00m\] "
All right a quick one to download and extract a .tar.gz archive in the current directory:
dluntar() { tar zxv < <(wget -q -O - $1) }
# usage
$ dluntar http://my.domain.com/archive.tar.gz
Oh, and I love Docker to test things:
sandbox() { docker run --rm -i -t deviantony/sandbox /bin/zsh }
Replace with your image ;)
I'm a big fan of peco to interactively grep lists, so here come a few of mines:
# pecohist show your command history and let you grep them, then copy your selection to your clipboard
alias hist="history | cut -c 8-"
pecohist() {
cmd=$(hist | peco | tr -d '\n')
$(echo $cmd | pbcopy)
echo $cmd
}
If you're using AWS a lot, ec2-cssh (I'm working on improving it, but it's already such a time saver) will let you list your ec2 instances (with their IPs, ids and tags) and automatically ssh into them, with a default key or the one you specify in args (requires aws cli, peco, jq)
function list_ec2s() {
local jq_query='.Reservations[] | .Instances[] | select(.State.Name != "terminated") | select(has("PublicIpAddress")) | [.PublicIpAddress,.PrivateIpAddress,.State.Name,(.Tags[] | select(.Key == "Name") | .Value // "")] | join("\t")'
aws ec2 describe-instances | jq -r $jq_query | peco
}
# Requires aws-cli, peco, jq and tmux-cssh (brew install it)
function ec2-cssh() {
local ssh_user=$2
local ssh_key=$1
local ip_addresses
# Default user
if [ -z ${ssh_user:+x} ]; then ssh_user="ec2-user"; fi
# Default key
if [ -z ${ssh_key:+y} ]; then ssh_key="~/.ssh/my_key.pem"; fi
ip_addresses=$(list_ec2s | awk '{ print $1 }' | tr '\n' ' ')
if [ -n $ip_addresses ]; then
echo "ssh -i ${ssh_key} ${ssh_user}@${ip_addresses}"
#sh -c "ssh -i $ssh_key ${ssh_user}@${ip_addresses}"
sh -c "tmux-cssh -u $ssh_user -i $ssh_key $ip_addresses"
fi
}
Easily display markdown in your console (when you're just looking for a sample command you know there, super easy to get it.... it's a man-like-formated markdown export displayed in less
# Markdown utilities (requires `brew install pandoc`)
function mdless () {
local mdfile=$1
if [ -z ${mdfile:+x} ]; then mdfile="README.md"; fi
case $mdfile in
-h | --help)
print "mdless usage: 'mdless myfile.md' or 'mdless' (defaults to README.md)"
;;
*)
mdcat $mdfile | less
;;
esac
}
function mdcat () {
local mdfile=$1
if [ -z ${mdfile:+x} ]; then mdfile="README.md"; fi
pandoc -s -f markdown -t man $mdfile | groff -T utf8 -man
}
If you're like me and have a tons of commands in the scripts node of your package.json, then list them to display an interactive list, and copy a npm run command of the selected one to your clipboard:
function npm_run(){
$(echo npm run $(cat package.json | jq -r '.scripts | keys' | grep '"' | sed 's/[",]//g' | peco | tr -d '\n' ) | pbcopy)
echo `pbpaste`
}
Hans-Helge Buerger
PHP, WordPress, JS Developer
I also have some aliases. Here are my favorites:
# Simply reload your bash configs to source changes or to update $PATH alias reload='clear; source ~/.zshrc' # Is the internet down? Simply check with a ping alias dping='ping duckduckgo.com' # What's the weather in Berlin? alias wetter='curl -4 wttr.in/Berlin' alias wttr='curl -s wttr.in/Berlin | head -7 | tail -5' # Save some letters ;) alias g='git'