Last active
April 10, 2020 13:06
-
-
Save Artistan/521ca722eac864f92f5a145eb7298099 to your computer and use it in GitHub Desktop.
Bash/ZSH Aliases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source .zsh.ssh.autocomplete.sh | |
alias l='ls -lahG' | |
# safety net aliases | |
alias cp='cp -iv' | |
alias mv='mv -iv' | |
alias rm='rm -i' | |
alias ln='ln -i' | |
# search aliases | |
alias grep='grep -n --color=auto' | |
alias grepr='grep -rn --color=auto' | |
alias loc='locate' | |
alias rgrep='grep -n --colour=always' | |
alias cgrep='grep --colour=always' | |
alias wgrep='rgrep --exclude=*.o --exclude=*.swp --exclude=*.in --exclude=.*~ --exclude-dir=.svn --exclude-dir=.git -m 1' | |
# window aliases | |
alias e='exit' | |
alias c='clear' | |
# git aliases | |
alias gs='git status' | |
alias gr='git remote -v' | |
# other commands aliases | |
alias h='history' | |
alias v='vim' | |
alias ah='cat ~/.aliases' | |
alias files='du -h --max-depth=1 | sort -h' | |
alias disks='lsblk' | |
alias mountit='~/mount.sh' | |
alias unmountit='~/unmount.sh' | |
# simple grep with color | |
alias g="grep --color --exclude=\*.svn\* -rnis " | |
# USE cg img; // will show 2 lines before and 15 lines after match. | |
alias cg="find . -path '*/.svn/*' -prune -o -path '*compiled*' -prune -o -type f -print | xargs -e grep -A 15 -B 2 --color -rnisIe " | |
# @example f img; find/grep | |
alias f="find . -path '*/.svn/*' -prune -o -path '*compiled*' -prune -o -type f -print | xargs -e grep --color -rnisIe " | |
# grep with line, file, color, no git/svn, no images, as text | |
alias grepp='grep --line-number --with-filename --color --exclude="*\.min*" --exclude-dir="\.{svn,git}" --text --exclude="*\.{png,jpg,jpeg,gif,new,bak,old,~}"' | |
# play a sound - usefull for `./dosomething && play` so you know it is done. | |
alias play='aplay /usr/share/skype/sounds/ContactAdded.wav' | |
# regex recursive find, without repo files @example `rf '(192|10)\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'` | |
alias rf="find . -path '*/.svn/*' -prune -o -path '*/.git/*' -prune -o -path '*compiled*' -prune -o -type f -print | xargs -e grep --color -Es " | |
# make `vi` open up vim... just because | |
alias vi="vim" | |
# get the processId list1 | |
alias processId="cut -d ' ' -f 4 /proc/self/stat" | |
# show grants for mysql (export grants) | |
# mygrants --host=prod-db1 --user=admin --password=secret | |
mygrants() | |
{ | |
mysql -B -N $@ -e "SELECT DISTINCT CONCAT( | |
'SHOW GRANTS FOR \'', user, '\'@\'', host, '\';' | |
) AS query FROM mysql.user" | \ | |
mysql $@ | \ | |
sed 's/\(GRANT .*\)/\1;/;s/^\(Grants for .*\)/## \1 ##/;/##/{x;p;x;}' | |
} | |
set_trap() { | |
QUIT=1 | |
} | |
use_trap() { | |
### Since 'wait $PID' can be interrupted by ^C, we need to protected it | |
### by the 'kill' loop ==> double/triple control-C problem. | |
#while kill -0 $PID >& /dev/null; do wait $PID; done | |
### This won't work (A simple wait $PID is vulnerable to double control C) | |
# wait $PID | |
if [ ! -z $QUIT ]; then | |
exit | |
fi | |
} | |
# catail_with_kill "/var/log/httpd/modsec_audit.log" 's/[^\/]*/\./;s/].*$//g' | |
catail_with_kill() { | |
trap set_trap SIGINT SIGTERM | |
if [[ -z "$1" || -z "$2" ]]; then | |
echo "catail \"/var/log/httpd/modsec_audit.log\" 's/[^\/]*/\./;s/].*$//g'" | |
return | |
fi | |
tail -f "$1" | while read line; do | |
( | |
echo "$line" | sed "$2" | awk '{print $0}' | xargs -n1 cat | |
) & | |
use_trap | |
done | |
return | |
} | |
# catail "/var/log/httpd/modsec_audit.log" 's/[^\/]*/\./;s/].*$//g' | |
catail() ( | |
if [[ -z "$1" || -z "$2" ]]; then | |
echo "catail \"/var/log/httpd/modsec_audit.log\" 's/[^\/]*/\./;s/].*$//g'" | |
return | |
fi | |
tail -f "$1" | while read line; do | |
echo "$line" | sed "$2" | awk '{print $0}' | xargs -n1 cat | |
done | |
) | |
alias bk='cd -' | |
alias vbox='cd ~/VirtualBox\ VMs/Configs/Homestead/' | |
export PATH="/Users/cpeterson/PhpstormProjects/spark-installer:/usr/local/opt/[email protected]/bin:/usr/local/opt/sqlite/bin:/usr/local/opt/curl/bin:$PATH:$HOME/.composer/vendor/bin" | |
export NODE_PATH='/usr/local/lib/node_modules' | |
zstyle ':completion:*:*:docker:*' option-stacking yes | |
zstyle ':completion:*:*:docker-*:*' option-stacking yes | |
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh" | |
# apple show hidden files | |
alias showFiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app' | |
# apple hide hidden files | |
alias hideFiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app' | |
# allow dropbox cli | |
alias dropbox-cli='~/bin/dropbox.py' | |
# ruby | |
source /usr/local/opt/chruby/share/chruby/chruby.sh | |
source /usr/local/opt/chruby/share/chruby/auto.sh | |
# add cert | |
alias add_cert='~/add-cert.sh' | |
# add sbin to exec path | |
export PATH="/usr/local/sbin:$PATH" | |
# https://gist.github.com/Artistan/e1da8a060900d5db3c3eb001e076b4e9 | |
# setup aliases for each of your boxes that you want to share publicly... this assumes ngrok_background.sh script in your home directory | |
alias homestead_public="~/ngrok_background.sh 192.168.10.11:80 homestead.test" | |
alias kill_ngrok="killall ngrok" | |
alias ngrok_status="$(curl -s http://localhost:4040/api/tunnels/command_line | jq -r --unbuffered)" | |
alias ngb="~/ngrok_background.sh" | |
## droplet helpers | |
# Retrieve an existing Domain | |
alias droplet_domain='curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $DROPLET_TOKEN" "https://api.digitalocean.com/v2/domains/${DOMAIN_NAME}" | jq' | |
# get records for the domain... | |
alias droplet_domain_records='curl -X GET -H "Content-Type: application/json" -d '{"per_page": "200"}' -H "Authorization: Bearer $DROPLET_TOKEN" "https://api.digitalocean.com/v2/domains/${DOMAIN_NAME}/records" | jq' | |
# update the record for the CNAME_ID you are looking for | |
alias droplet_update_cname='curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $DROPLET_TOKEN" -d "{\"data\":\"${WEBHOOK_DOMAIN}.\"}" "https://api.digitalocean.com/v2/domains/${DROPLET_DOMAIN_NAME}/records/${DROPLET_CNAME_ID}" | jq' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export DROPLET_TOKEN="xx" | |
export DROPLET_DOMAIN_NAME="x.com" | |
export DROPLET_CNAME_ID="xxxx" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.codyhiar.com/blog/zsh-autocomplete-with-ssh-config-file/ | |
# usage ... `s` tab.... autocompletes from your .ssh/config file... | |
alias s='ssh' | |
# Highlight the current autocomplete option | |
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" | |
# Better SSH/Rsync/SCP Autocomplete | |
zstyle ':completion:*:(scp|rsync):*' tag-order ' hosts:-ipaddr:ip\ address hosts:-host:host files' | |
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost | |
zstyle ':completion:*:(ssh|scp|rsync):*:hosts-ipaddr' ignored-patterns '^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))' '127.0.0.<->' '255.255.255.255' '::1' 'fe80::*' | |
# Allow for autocomplete to be case insensitive | |
zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' \ | |
'+l:|?=** r:|?=**' | |
# Initialize the autocompletion | |
autoload -Uz compinit && compinit -i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
..... | |
source .secrets.sh | |
source .aliases.sh | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment