-
-
Save riccop/fd45851a9e0fc2648c71cf038c4029fb to your computer and use it in GitHub Desktop.
Alias for bash
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
# ~/.bashrc: executed by bash(1) for non-login shells. | |
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) | |
# for examples | |
# some more ls aliases | |
alias ll='ls -alF' | |
alias la='ls -A' | |
alias l='ls -CF' | |
alias gs='git status ' | |
alias ga='git add ' | |
alias gaa='git add -A ' | |
alias gb='git branch ' | |
alias gc='git commit ' | |
alias gcm='git commit -m ' | |
alias go='git checkout ' | |
alias beevo_env_rabbit_reset='docker exec -it docker-beevo_rabbit_1 bash -c "rabbitmqctl stop_app && rabbitmqctl reset && rabbitmqctl start_app"' | |
alias beevo_env_rabbit_bash_root='docker exec -it docker-beevo_rabbit_1 bash' | |
# Add an "alert" alias for long running commands. Use like so: | |
# sleep 10; alert | |
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' | |
# sudo apt install gnustep-gui-runtime | |
# alias alert_talk='wc -l imdb.nt ; say $1' | |
# Usage: alert_talk "OLA MUNDO 123 456 FIM" | |
alias alert_say='say $1' | |
# Alias definitions. | |
# You may want to put all your additions into a separate file like | |
# ~/.bash_aliases, instead of adding them here directly. | |
# See /usr/share/doc/bash-doc/examples in the bash-doc package. | |
if [ -f ~/.bash_aliases ]; then | |
. ~/.bash_aliases | |
fi | |
PROJECTS_PATH=$(realpath ~/workplace/www) | |
DOCKER_PATH=$(realpath ~/workplace/docker-beevo-new) | |
DUMP_PATH="db_dump" | |
CONTAINER_WEB='docker-beevo-new_php_1' | |
CONTAINER_MYSQL='docker-beevo-new_db_1' | |
MYSQL_USER='root' | |
MYSQL_PASS='oveeb' | |
EDITOR_ALIAS='code' | |
RED='\e[1;31m' | |
GRN='\e[1;32m' | |
YWL='\e[1;33m' | |
BLUE='\e[1;36m' | |
MAG='\e[1;35m' | |
END='\e[0m' | |
alias up="cd $DOCKER_PATH && docker-compose up -d && cd - && docker image prune -a" | |
alias start="cd $DOCKER_PATH; docker-compose start; cd -" | |
alias www="cd $PROJECTS_PATH" | |
alias addChmod="cd $PROJECTS_PATH && sudo chmod -" | |
function down(){ | |
if [ "$1" = "-h" ]; then | |
echo && echo " down [?container]" | |
return | |
fi | |
local ALL=$(docker ps -a -q) | |
docker stop ${1:-$ALL} && docker rm ${1:-$ALL} | |
} | |
function dexec() { | |
if [ "$1" = "-h" ] || [ -z "$1" ]; then | |
echo && echo " dexec [container =web, =mysql] [command]" | |
return | |
fi | |
case $1 in | |
web) | |
CONTAINER=$CONTAINER_WEB;; | |
mysql) | |
CONTAINER=$CONTAINER_MYSQL;; | |
*) | |
CONTAINER=$1;; | |
esac | |
docker exec -it $CONTAINER "${@:2}" | |
} | |
function web(){ | |
if [ "$1" = "-h" ]; then | |
echo && echo " web [project] [?command =tail, =migrate, =repair, =preload [?options], =update [?options], =migration [app] [JIRA ISSUE] [DESCRIPTION] [AUTHOR]]" | |
return | |
fi | |
case $2 in | |
"") | |
dexec web bash -c "cd ${1:-/var/www/html/} && bash";; | |
update) | |
dexec web bash -c "cd $1 && beevo update-project ${*:3}";; | |
migrate) | |
dexec web bash -c "cd $1 && beevo run-migrations migrate";; | |
repair) | |
dexec web bash -c "cd $1 && beevo run-migrations repair";; | |
versions) | |
dexec web bash -c "cd $1 && beevo update-versions";; | |
preload) | |
dexec web bash -c "cd $1 && rm -rf beevo/cache beevo/preload && beevo preload ${*:3}";; | |
tail) | |
dexec web bash -c "cd $1 && tail -f logs/beevo.log";; | |
merge) | |
dexec web bash -c "cd $1 && bv_mergefile";; | |
migration) | |
local STEP1=$(curl -s http://api.manager.beevo.com/v1/installables/$3/versions | grep -Po '"version":.*?[^\\]",' | tail -1) | |
local STEP2=${STEP1#*\"version\":\"v} | |
local STEP3=${STEP2%\",} | |
local VERSION=${STEP3//.} | |
STEP1=$(curl -s http://api.manager.beevo.com/v1/installables/$3 | grep -Po '"installableId":.*?[^\\]",') | |
STEP2=${STEP1#*\"installableId\":\"} | |
local APP_NUMBER=${STEP2%\",} | |
printf "\nAutomatically Added\n${GRN}App Number:$END $APP_NUMBER" | |
printf "\n${GRN}Version:$END $VERSION\n\n" | |
dexec web bash -c "cd $1/apps/$3/*/Install && beevo generate-migration $APP_NUMBER $VERSION ${*:4}" | |
local MIGRATION=$(ls -t $PROJECTS_PATH/$1/apps/$3/*/Install | head -1) | |
if ! [ -z "$4" ]; then | |
b_open $1 $3 /*/Install/$MIGRATION | |
fi | |
;; | |
*) | |
dexec web bash -c "cd $1 && ${*:2}";; | |
esac | |
} | |
function pv(){ | |
if [ "$1" = "-h" ] || [ -z "$1" ]; then | |
echo && echo " pv [dump] [DB] [?username] [?password]" | |
return | |
fi | |
if [[ $1 != *.sql.gz ]] && [[ $1 != *.sql ]]; then | |
echo && echo " The file must ends with .sql or .sql.gz" | |
return | |
fi | |
if [[ $1 == *.sql.gz ]]; then | |
dexec mysql bash -c "pv $DUMP_PATH/$1 | zcat | mysql -f -u${3:-$MYSQL_USER} -p${4:-$MYSQL_PASS} $2" | |
else | |
dexec mysql bash -c "pv $DUMP_PATH/$1 | mysql -f -u${3:-$MYSQL_USER} -p${4:-$MYSQL_PASS} $2" | |
fi | |
notify-send " > Import completed π‘ " "The import of the database was finished!" | |
} | |
function docs(){ | |
if [ "$1" = "-h" ] || [ -z "$1" ]; then | |
echo && echo " docs [project] [app] [?version]" | |
return | |
fi | |
dexec web bash -c "cd $1/apps/$2/* && beevo docs-compare --namespace $2 --version ${3:-\$(git describe --abbrev=0 --match 'v[0-9]*')} --print" | |
} | |
function b_clone(){ | |
if [ "$1" = "-h" ] || [ -z "$1" ]; then | |
echo && echo " b_clone [repo name] [project]" | |
return | |
fi | |
cd "$PROJECTS_PATH/$2/apps/$1" && \ | |
local VERSION="$(find -maxdepth 1 -type d -name '*_*' -print -quit)" && \ | |
sudo rm -rf $VERSION && \ | |
git clone git@bitbucket.org:bsolus_daredevil/$1.git $VERSION | |
cd - | |
} | |
function b_open(){ | |
if [ "$1" = "-h" ] || [ -z "$1" ]; then | |
echo && echo " b_open [project] [?app]" | |
return | |
fi | |
if [ -z "$2" ]; then | |
$EDITOR_ALIAS $PROJECTS_PATH/$1 | |
return | |
fi | |
sudo $EDITOR_ALIAS --user-data-dir="~/.vscode-root" $PROJECTS_PATH/$1/apps/$2${3-/*} | |
} | |
function b_tag(){ | |
if [ "$1" = "-h" ] || [ -z "$1" ]; then | |
echo && echo " b_tag [app] [version] [?project(to validate docs)]" | |
return | |
fi | |
if ! [ -z "$3" ]; then | |
docs $3 $1 | |
printf "\n${END}Check for errors inside the doc array β\n" | |
local CONFIRMATION="0" | |
while [ "$CONFIRMATION" != "y" ]; do | |
printf "\nDo you want to tag this app? [y/n]: " | |
read CONFIRMATION | |
if [ "$CONFIRMATION" = "n" ]; then | |
return | |
fi | |
done | |
fi | |
echo && curl -s -X POST -F "version=$2" http://api.manager.beevo.com/v1/installables/$1/versions/ && echo && \ | |
curl -s -X POST http://api.manager.beevo.com/v1/installables/$1/versions/$2/checkdependencies | |
printf "\n\nLoading " | |
while : ; do | |
sleep 1 | |
local STEP1=$(curl -s http://api.manager.beevo.com/v1/installables/$1/versions/$2 | grep -Po '"lastMessage":.*?[^\\]",') | |
local STEP2=${STEP1#*\"lastMessage\":\"} | |
local STEP3=${STEP2%\",} | |
printf "." | |
[ "${STEP3:0:1}" = "\"" ] || break | |
done | |
printf "\n\nResponse: $BLUE$STEP3$END\n" | |
} | |
alias b_info='down -h && dexec && web -h && pv && docs && b_clone && b_open && b_tag' | |
_downComplete() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local prev=${COMP_WORDS[COMP_CWORD-1]} | |
case ${COMP_CWORD} in | |
1) | |
COMPREPLY=( $(compgen -W "$(docker ps -a --format "{{.Names}}")" -- $cur) ) | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
_dexecComplete() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local prev=${COMP_WORDS[COMP_CWORD-1]} | |
case ${COMP_CWORD} in | |
1) | |
COMPREPLY=( $(compgen -W "web mysql" -- $cur) ) | |
COMPREPLY+=( $(compgen -W "$(docker ps -a --format "{{.Names}}")" -- $cur) ) | |
;; | |
2) | |
COMPREPLY=( $(compgen -W "[command]" -- $cur) ) | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
_webComplete() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local prev=${COMP_WORDS[COMP_CWORD-1]} | |
case ${COMP_CWORD} in | |
1) | |
COMPREPLY=( $(compgen -W "$(ls $PROJECTS_PATH)" -- $cur) ) | |
;; | |
2) | |
COMPREPLY=( $(compgen -W "tail migrate repair preload update merge migration" -- $cur) ) | |
;; | |
3) | |
case ${prev} in | |
preload|update) | |
COMPREPLY=($(compgen -W "[?options]" -- ${cur})) | |
;; | |
migration) | |
COMPREPLY=($(compgen -W "$(ls $PROJECTS_PATH/${COMP_WORDS[1]}/apps)" -- ${cur})) | |
;; | |
esac | |
;; | |
4) | |
case ${COMP_WORDS[COMP_CWORD-2]} in | |
migration) | |
COMPREPLY=($(compgen -W "[JIRA_ISSUE][DESCRIPTION][AUTHOR]" -- ${cur})) | |
;; | |
esac | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
_pvComplete() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local prev=${COMP_WORDS[COMP_CWORD-1]} | |
case ${COMP_CWORD} in | |
1) | |
COMPREPLY=( $(compgen -W "$(ls $PROJECTS_PATH/$DUMP_PATH)" -- $cur) ) | |
;; | |
2) | |
COMPREPLY=( $(compgen -W "[DB][?username][?password]" -- $cur) ) | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
_docsComplete() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local prev=${COMP_WORDS[COMP_CWORD-1]} | |
case ${COMP_CWORD} in | |
1) | |
COMPREPLY=( $(compgen -W "$(ls $PROJECTS_PATH)" -- $cur) ) | |
;; | |
2) | |
COMPREPLY=( $(compgen -W "$(ls $PROJECTS_PATH/$prev/apps)" -- $cur) ) | |
;; | |
3) | |
COMPREPLY=( $(compgen -W "[?version]" -- $cur) ) | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
_cloneComplete() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local prev=${COMP_WORDS[COMP_CWORD-1]} | |
case ${COMP_CWORD} in | |
1) | |
local NAMESPACE=$(curl -s http://api.manager.beevo.com/v1/installables | grep -Po '"namespace":.*?[^\\]",' | sed 's/\"namespace\":\"//g' | sed 's/\",//g' ) | |
COMPREPLY=( $(compgen -W "$NAMESPACE" -- $cur) ) | |
;; | |
2) | |
COMPREPLY=( $(compgen -W "$(ls $PROJECTS_PATH)" -- $cur) ) | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
_openComplete() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local prev=${COMP_WORDS[COMP_CWORD-1]} | |
case ${COMP_CWORD} in | |
1) | |
COMPREPLY=( $(compgen -W "$(ls $PROJECTS_PATH)" -- $cur) ) | |
;; | |
2) | |
COMPREPLY=( $(compgen -W "$(ls $PROJECTS_PATH/$prev/apps)" -- $cur) ) | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
_tagComplete() | |
{ | |
local cur=${COMP_WORDS[COMP_CWORD]} | |
local prev=${COMP_WORDS[COMP_CWORD-1]} | |
case ${COMP_CWORD} in | |
1) | |
local NAMESPACE=$(curl -s http://api.manager.beevo.com/v1/installables | grep -Po '"namespace":.*?[^\\]",' | sed 's/\"namespace\":\"//g' | sed 's/\",//g' ) | |
COMPREPLY=( $(compgen -W "$NAMESPACE" -- $cur) ) | |
;; | |
2) | |
local STEP1=$(curl -s http://api.manager.beevo.com/v1/installables/${COMP_WORDS[1]}/versions | grep -Po '"version":.*?[^\\]",' | tail -1) | |
local STEP2=${STEP1#*\"version\":\"} | |
local VERSION=${STEP2%\",} | |
COMPREPLY=( $(compgen -W "$VERSION" -- $cur) ) | |
;; | |
3) | |
COMPREPLY=( $(compgen -W "$(ls $PROJECTS_PATH)" -- $cur)) | |
;; | |
*) | |
COMPREPLY=() | |
;; | |
esac | |
} | |
complete -F _downComplete down | |
complete -F _dexecComplete dexec | |
complete -F _webComplete web | |
complete -F _pvComplete pv | |
complete -F _docsComplete docs | |
complete -F _cloneComplete b_clone | |
complete -F _openComplete b_open | |
complete -F _tagComplete b_tag | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
base_dir() { | |
basename `pwd` | |
} | |
alias srcBashRc="source ~/.bashrc" | |
alias fg="flameshot gui" | |
# BASH PS1 | |
# EMOJIS=(πΊ πΈ πΉ π» πΌ π½ π πΏ πΎ) | |
EMOJIS=(π π» β πΆ π π π© π π π πΎ π‘ β π π πΎ) | |
RANDOM_EMOJI() { | |
SELECTED_EMOJI=${EMOJIS[$RANDOM % ${#EMOJIS[@]}]}; | |
echo $SELECTED_EMOJI; | |
} | |
# https://makandracards.com/makandra/1090-customize-your-bash-prompt | |
PS1='\[\033[01;30m\]\t `if [ $? = 0 ]; then echo "\[\033[01;32m\]γ"; else echo "\[\033[01;31m\]β"; fi` \[\033[00;32m\]\u@\h\[\033[00;37m\]:\[\033[31m\]$(parse_git_branch "(%s)\[\033[01m\]")\[\033[00;34m\]\W\[\033[00m\] $(RANDOM_EMOJI) >' | |
# PS1='\033[32m${debian_chroot:+($debian_chroot)}\u@\h:\W \033[33m$(git_branch) $(RANDOM_EMOJI) \033[35m\$ ' | |
# Bash utils | |
# \u: current username | |
# \h: hostname up to the first ., \H: full hostname | |
# \w: current working directory, \W: same, but only the basename | |
# $(__git_ps1 "%s"): your current git branch if you're in a git directory, otherwise nothing | |
# \$: if the effective UID is 0: #, otherwise $ | |
# \d: the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
# \t: the current time in 24-hour HH:MM:SS format, \T: same, but 12-hour format, \@: same, but in 12-hour am/pm format | |
# \n: newline | |
# \r: carriage return | |
# \\: backslash | |
# Colors & Styles | |
# colors have to be escaped (see General), color codes should be followed by an m | |
# put \[\e[βΉcodeβΊm\] and \[\e[0m\] around the part of your prompt you want to style | |
# where βΉcodeβΊ is a ;-chain of: | |
# x: attribute of the text | |
# 3y: foreground color | |
# 4y: background color | |
# x: | |
# 0: normal | |
# 1: bold | |
# 4: underline | |
# 7: reverse | |
# y is the color: | |
# 0 black | |
# 1 red | |
# 2 green | |
# 3 yellow | |
# 4 blue | |
# 5 magenta | |
# 6 cyan | |
# 7 white | |
# example: \[\e[0;33m\]prompt:\[\e[0m\] | |
# Save your settings by writing export PS1='...' to your .bashrc or .profile. | |
# enable bash completion in interactive shells | |
if ! shopt -oq posix; then | |
if [ -f /usr/share/bash-completion/bash_completion ]; then | |
. /usr/share/bash-completion/bash_completion | |
elif [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
fi | |
fi | |
# Free space command | |
freeSpace() { | |
printf "Get rid of packages that are no longer required \n\n" | |
sudo apt-get autoremove | |
printf "\n\nClean up APT cache in Ubuntu\n\n" | |
sudo du -sh /var/cache/apt | |
sudo apt-get autoclean | |
sudo apt-get clean | |
printf "\n\nClean the thumbnail cache\n\n" | |
du -sh ~/.cache/thumbnails | |
rm -rf ~/.cache/thumbnails/* | |
# TODO : Remove old Linux kernels that were manually installed ( need some advance knolege carefull ... ) sudo dpkg --list 'linux-image*' sudo apt-get remove linux-image-VERSION replace version ... | |
# TODO : Remove orphaned packages ( need some advance knowledge ) sudo apt-get install gtkorphan. ( cannot free mutch space with this anyway ...) | |
# Uninstalling unnecessary applications ... -> sudo apt-get remove package-name1 package-name2 | |
# TODO : check duplicateds ... check fdupes ... find duplicateds ... | |
printf "\n\nRemove old kernels a) are no longer needed and b) were installed from the Ubuntu archive through systems updates\n\\n" | |
sudo apt-get autoremove --purge | |
printf "\n\nRemove older versions of Snap applications \n\n" | |
du -h /var/lib/snapd/snaps | |
bash freeSpace.sh | |
du -h /var/lib/snapd/snaps | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment