Last active
February 13, 2022 22:34
-
-
Save SmetDenis/7292d4a0b06739b3a5b9e6fcfb6e9b1e 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
################ copy/replace file to ~/.bash_aliases | |
################ Tuning bash ########################################################################################### | |
# Command line history | |
export HISTCONTROL=ignoredups:ignorespace | |
export HISTFILESIZE=10000000 | |
export HISTSIZE=1000000 | |
shopt -s histappend # Append to the history file, don't overwrite it | |
shopt -s checkwinsize # Check the window size after each command and, if necessary, update the values of LINES and COLUMNS. | |
# Editor | |
export EDITOR=mcedit | |
alias edit='/usr/bin/mcedit' | |
# Colored console | |
export CLICOLOR=1 | |
export LSCOLORS=ExFxBxDxCxegedabagacad | |
################ Global Env variables ################################################################################## | |
export COMPOSER_ALLOW_SUPERUSER=1 | |
################ Colors ################################################################################################ | |
Blue='\[\e[01;34m\]' | |
White='\[\e[01;37m\]' | |
Red='\[\e[01;31m\]' | |
Green='\[\e[01;32m\]' | |
Cyan='\[\e[01;36m\]' | |
Purple='\[\e[01;35m\]' | |
Gray='\[\e[01;30m\]' | |
UsernameColor=$Green | |
Reset='\[\e[00m\]' | |
# Icons | |
FancyX='\342\234\227' | |
CheckMark='\342\234\223' | |
################ Command line: PROMPT & PS1 ############################################################################ | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
parse_git_tag() { | |
git describe --abbrev=0 --tags 2> /dev/null | |
} | |
set_prompt () { | |
Last_Command=$? # Must come first! | |
PS1="$White\$? " | |
if [[ $Last_Command == 0 ]]; then | |
PS1+="$Green$CheckMark " | |
else | |
PS1+="$Red$FancyX " | |
fi | |
if [[ $EUID == 0 ]]; then | |
PS1+="$Red\\u@`hostname` (ROOT!) " | |
else | |
PS1+="$UsernameColor\\u@`hostname` " | |
fi | |
PS1+="$Blue\\w $Reset" | |
PS1+="\033[36m\]`parse_git_branch`\[\033[00m\] $Gray`parse_git_tag`\n$Blue\$$Reset " | |
} | |
PROMPT_COMMAND='set_prompt' | |
################ Admin Tools ########################################################################################### | |
# Midnight commander | |
alias mc='/usr/lib/mc/mc-wrapper.sh' | |
alias _mc='sudo mc' | |
# Make | |
alias make="make --no-print-directory" | |
alias _make="sudo make --no-print-directory" | |
# PHP | |
alias phpi='php -i | grep ' | |
# Other tools | |
alias _ntp='sudo ntpdate -s ntp.ubuntu.com' | |
alias _backup='sudo backup-manager -v' | |
alias ttop="top -R -F -s 10 -o rsize" # Recommended 'top' invocation to minimize resources | |
alias which='type -all' | |
alias ex='exit' | |
# Hosts | |
alias hosts-edit='sudo edit /etc/hosts' # Edit /etc/hosts file | |
alias hosts-reload='sudo dscacheutil -flushcache' # Flush out the DNS Cache | |
# Server info | |
alias df='df -H' | |
alias du='du -ch' | |
alias path='echo -e ${PATH//:/\\n}' | |
# Tests | |
testFs() { | |
sudo time dd if=/dev/zero of=./test bs=1M count=500; | |
sudo rm test; | |
} | |
testSys() { | |
echo "Load average: `cat /proc/loadavg`" | |
echo -en "Memory: $(( `sed -n "s/MemFree:[\t ]\+\([0-9]\+\) kB/\1/p" /proc/meminfo`/1024)) / $((`sed -n "s/MemTotal:[\t ]\+\([0-9]\+\) kB/\1/Ip" /proc/meminfo`/1024 ))MB \n" | |
} | |
testUptime () { | |
echo -ne "Uptime is \t "; uptime | awk /'up/ {print $3,$4,$5,$6,$7,$8,$9,$10}' | |
} | |
# linux tools | |
alias apt='sudo apt' | |
alias apt-get='sudo apt-get' | |
alias apt-up='sudo apt update; sudo apt upgrade; sudo apt-get autoremove'; | |
alias service='sudo service'; | |
# Bash Tools | |
alias bup='source ~/.bashrc; echo "~/.bashrc was reloaded"' | |
alias alias-edit='mcedit ~/.bash_aliases; bup' | |
alias c='clear' | |
alias hh='history | gr ' | |
# complete -W "\`grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' Makefile | sed 's/[^a-zA-Z0-9_-]*$//'\`" make | |
complete -W "\`make autocomplete\`" make | |
# Dirs | |
alias ls='ls -Alv --color=auto --group-directories-first --show-control-chars --human-readable --time-style=long-iso --indicator-style=slash' | |
alias lr='/bin/ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less' | |
alias cd..='cd ..' | |
alias ..='cd ..' | |
alias ...='cd ../../' | |
alias ....='cd ../../../' | |
alias .....='cd ../../../../' | |
alias h='cd ~' | |
# Colorize the grep command output for ease of use (good for log files) | |
alias grep='/bin/grep -i --color=auto' | |
alias gr='/bin/grep -i --color=auto' | |
alias egrep='egrep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
# Archives | |
zipf() { zip -r9q "$1".zip "$1"; } | |
extract() { | |
if [ -f $1 ]; then | |
case $1 in | |
*.tar.bz2) tar xvjf $1 ;; | |
*.tar.gz) tar xvzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) rar x $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xvf $1 ;; | |
*.tbz2) tar xvjf $1 ;; | |
*.tgz) tar xvzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*) echo "don't know how to extract '$1'..." ;; | |
esac | |
else | |
echo "'$1' is not a valid file!" | |
fi | |
} | |
# Search | |
alias f='find -name ' | |
function ff() { find . -type f -iname '*'$*'*' -ls; } | |
function fe() { find . -type f -iname '*'$1'*' -exec "${2:-file}" {} \;; } | |
function fstr() { | |
find $1 -type f -exec grep -Hn "$2" {} \; | grep $2 | |
} | |
# HTTP tools | |
http-headers () { /usr/bin/curl -I -L $@ ; } | |
http-debug () { /usr/bin/curl $@ -o /dev/null -w "dns: %{time_namelookup} connect: %{time_connect} pretransfer: %{time_pretransfer} starttransfer: %{time_starttransfer} total: %{time_total}\n" ; } | |
################ Dirs, files, locations ################################################################################ | |
alias mkdir='mkdir -pv' | |
mk() { mkdir $1; cd ./$1; } | |
alias rm='rm -i --preserve-root' | |
alias rm-ds="find . -name '.DS_Store' -type f -delete" | |
alias mv='mv -i' | |
alias cp='cp -i' | |
alias ln='ln -i' | |
dir-size() { du -h -s $1; } | |
alias dir-rw='sudo chmod -R g+w' | |
alias dir-www-data='sudo chown -R www-data:www-data' | |
################ Utils ################################################################################################# | |
alias co="composer" | |
alias co-i="composer require" | |
alias co-u="composer update --no-progress" | |
alias co-ig="composer global require" | |
alias co-ug="sudo composer global update --no-progress" | |
# Bower | |
alias bo-i='bower install --save' | |
alias bo-u='bower update --force-latest --allow-root' | |
# NPM | |
alias n-i="npm install --save" | |
# Restart services | |
alias re-php='sudo service php7.2-fpm restart' | |
alias re-nginx='sudo nginx -t && sudo service nginx restart' | |
alias re-mysql='sudo service mysql restart' | |
alias re-cron='sudo service cron restart' | |
alias re-web='re-php; re-nginx; re-mysql; re-cron'; | |
# Show logs in real time | |
alias tail='tail -F' | |
alias logs-nginx='tail /var/log/nginx/error.log' | |
alias logs-mysql='tail /var/log/mysql/error.log' | |
alias logs-php='tail /var/log/php7.2-fpm.log' | |
alias logs-auth='tail /var/log/auth.log' | |
alias logs-sys='tail /var/log/syslog' | |
# Docker | |
alias docker="sudo docker" | |
function docker-e() { | |
sudo docker exec -it $1 bash | |
} | |
# Git | |
alias g-l="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit" | |
alias g-s='git status' | |
alias g-a='git add ' | |
alias g-d='git diff --stat ' | |
alias g-pl='git pull --rebase' | |
alias g-rc='git rebase --continue' | |
alias g-po='git push origin ' | |
alias g-b='git branch ' | |
alias g-f='git fetch ' | |
alias g-co='git checkout ' | |
alias g-ca='git commit -a -m ' | |
alias g-k='gitk --all & ' | |
alias g-g='gitg &' | |
alias g-p='git push' | |
alias g-c='git commit -v -m ' | |
alias g-ba='git branch -a' | |
alias g-res='git reset --hard' | |
echo ' - Custom aliases loaded!' | |
cd ~/www |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment