Last active
August 22, 2020 16:00
-
-
Save dccampbell/ee961d59d3889851d58036bc4a232ff3 to your computer and use it in GitHub Desktop.
This file contains 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
# Variables | |
COMPOSER_HOME="$HOME/.composer" | |
HOSTS='/etc/hosts' | |
VHOST='/etc/apache2/sites-available/localdev.conf' | |
ERRLOG='/var/log/apache2/error.log' | |
# Fix SSH xterm-256color issue | |
alias ssh='TERM=xterm-color ssh' | |
# File Shortcuts | |
alias edit-hosts='sudo nano $HOSTS' | |
alias edit-vhost='sudo nano $VHOST' | |
alias errlog='cat $ERRLOG' | |
# List Aliases | |
alias ls='ls -h --color' # Human-readable | |
alias lx='ls -lXB' # Sort by extension. | |
alias lk='ls -lSr' # Sort by size, biggest last. | |
alias lt='ls -ltr' # Sort by date, most recent last. | |
alias lc='ls -ltrc' # Sort by/show change time, most recent last. | |
alias lu='ls -ltru' # Sort by/show access time, most recent last. | |
alias ll='ls -lv --group-directories-first' # Dirs first, alphanumeric sort | |
alias lr='ls -lvR --group-directories-first' # Dirs first, alphanumeric sort, recursive | |
alias la='ls -lvA --group-directories-first' # Dirs first, alphanumeric sort, show hidden | |
# Grep Aliases | |
alias grepv='grep -Eiv --color' | |
alias grepe='grep -Ei --color' | |
alias errorsFromSystemLog='grep "ERR (3):" | cut -d" " -f2- | sort | uniq' | |
alias errorsFromExceptionLog='grep -A1 "ERR (3):" | grep -v "ERR (3):" | sort | uniq' | |
# Sounds/Bell Aliases | |
alias sound-list='ls /usr/share/sounds/freedesktop/stereo/' | |
alias bell-sound='paplay /usr/share/sounds/freedesktop/stereo/$([ $? = 0 ] && echo complete || echo dialog-warning).oga' | |
alias bell-notif='notify-send -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*bell$//'\'')"' | |
alias bell='bell-sound;bell-notif' | |
sound() { paplay /usr/share/sounds/freedesktop/stereo/${1:-bell}.oga; } | |
# Misc | |
alias apache-restart='sudo service apache2 restart' | |
alias artisan='php artisan' | |
alias dmesge="dmesg -Hx --level=emerg,alert,crit,err,warn" | |
alias flat-install='flatpak install flathub' | |
alias npmi-clean='rm -rf ./node_modules/ ./package-lock.json; npm install' | |
alias synergy-restart='sudo service synergy restart' | |
alias untar='tar -xf' | |
alias untargz='tar -xzf' | |
alias vagrants='vagrant global-status' | |
alias vagrant-refresh='vagrant destroy -f && date && vagrant up && date; bell' | |
# Functions | |
downloadFile() { | |
FILE="${2:-$(basename "$1")}" | |
wget "$1" -O "$FILE" || rm "$FILE" | |
} | |
installDeb() { | |
cd $HOME/Downloads | |
downloadFile "$1" $2 && sudo -E dpkg -i "$FILE" | |
} | |
setDebConf() { | |
echo $@ | sudo debconf-set-selections | |
} | |
addSource() { # Usage: addSource <line> <filename> [keyUrl] | |
echo "$1" | sudo tee "/etc/apt/sources.list.d/$2" | |
[ -n "$3" ] && downloadFile "$3" && sudo apt-key add "$FILE" || echo "[ERR] addSource $1"; | |
} | |
checkPerms() { | |
for dir in "$@"; do | |
printf "\n$ ls -al $dir \n" && ls -al $dir; | |
printf "\n$ ls -dZ $dir \n" && ls -dZ $dir; | |
printf "\n$ getfacl $dir \n" && getfacl $dir; | |
done | |
} | |
apply-diff() { | |
patch -p1 --input=$1 | |
} | |
git-fixdate() { | |
if [[ $# -ne 2 ]]; then | |
git filter-branch --env-filter \ | |
"if test \$GIT_COMMIT = '$1'; then | |
export GIT_AUTHOR_DATE | |
export GIT_COMMITTER_DATE | |
GIT_AUTHOR_DATE='$2' | |
GIT_COMMITTER_DATE='$2' | |
fi" && | |
rm -fr "$(git rev-parse --git-dir)/refs/original/" | |
fi | |
} | |
git-fixcrlf() { | |
for FILE in $(git diff --name-only HEAD); do | |
dos2unix $FILE; | |
done | |
git add -u | |
} | |
git-fixperm() { | |
git diff -p -R --no-color | grep -E "^(diff|(old|new) mode)" --color=never | git apply | |
} | |
splitByDate() { | |
while read; do | |
[[ $REPLY =~ ^(....)-(..)-(..)T ]] | |
echo "$REPLY" >> "$1.$(printf "%s-%s-%s" "${BASH_REMATCH[@]:1:3}").log" | |
done < $1 | |
} | |
servephp() { | |
php -S 0.0.0.0:${1:-8000} | |
} | |
composer-refresh() { | |
[[ -f './composer.json' ]] || { echo 'composer.json not found in current directory'; return 1; } | |
( | |
set -x | |
composer clear-cache | |
rm -rf ./vendor | |
composer update | |
) | |
} | |
db-create() { | |
echo "CREATE DATABASE $1;" | mysql -uroot -ppass | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment