Last active
July 29, 2025 13:41
-
-
Save Max95Cohen/0cfafd308fab1c2e4e32e4a69fe6b5e0 to your computer and use it in GitHub Desktop.
.bashrc doker-compose bash script
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
| alias compose-ps="docker ps --format 'table {{ .Names }}\t{{ .Status }}\t{{ .Label \"com.docker.compose.project\" }}\t{{ .Label \"com.docker.compose.service\" }}\t{{ .Label \"com.docker.compose.project.working_dir\" }}'" | |
| alias dps="docker ps -a --format 'ID: {{.ID}}\nNames: {{.Names}}\nProject: {{.Label \"com.docker.compose.project\"}}\nPorts: {{.Ports}}\nStatus: {{.Status}}\n'" | |
| dc() { | |
| project=$1 | |
| container=$2 | |
| check=echo $project | grep "laravel" | |
| if [ -z $check ]; then | |
| path="frontend" | |
| if [ -z $container ]; then | |
| container="phalcon" | |
| path="api" | |
| fi | |
| if [ ! -z $1 ] && [ $1 != "dev" ]; then | |
| project=echo $1 | tr '[:lower:]' '[:upper:]' | |
| fi | |
| else | |
| container="laravel" | |
| path="frontend" | |
| project="" | |
| fi | |
| path_=$path | |
| if [ -z $project ]; then | |
| path=~/$path | |
| else | |
| if [ $1 == 'dev' ]; then | |
| path="/var/www/$path" | |
| else | |
| path="/var/www/builds/$path/$project" | |
| fi | |
| fi | |
| cd $path | |
| if [ ! -z $project ]; then | |
| project="-p ${project}_$path_" | |
| fi | |
| docker-compose $project exec $container bash | |
| } | |
| rmproject() { | |
| NGINX_FILE=/etc/nginx/sites-enabled/dev.conf | |
| for i in $(grep "\/$1\/" $NGINX_FILE -on | cut -d ':' -f1); do | |
| END_LINE2=$(($i + 10)) | |
| CLOSED_BRACKETS=$(sed -n "$i,${END_LINE2}p" $NGINX_FILE | grep -n '}' | cut -d ':' -f1) | |
| CLOSED_BRACKETS=$(($CLOSED_BRACKETS - 1)) | |
| END_LINE=$(($i + $CLOSED_BRACKETS)) | |
| echo $i $END_LINE | |
| sudo sed -i "$i,$END_LINE s/^/#/" $NGINX_FILE | sed -n "$i,${END_LINE2}p" | |
| done; | |
| BRANCH=`echo $1 | tr '[:lower:]' '[:upper:]'` | |
| echo $BRANCH | |
| CONTAINERS=$(docker ps -aqf name=$BRANCH) | |
| if [[ ! -z $CONTAINERS ]]; then docker stop $(docker ps -aqf name=$BRANCH); fi | |
| sudo rm /etc/nginx/sites-enabled/${BRANCH}.* | |
| } | |
| getports() { | |
| for i in $(netstat -tulpn | grep 0.0.0.0:111 | awk '{print $4}' | sort); do | |
| port=$(echo $i | sed "s/0.0.0.0:111//"); | |
| echo $port | |
| done | |
| } | |
| freeports() { | |
| start=11101 | |
| end=11199 | |
| for port in $(seq $start $end); do | |
| if ! ss -tuln | grep -q ":$port\b"; then | |
| echo "First available port: $port" | |
| break | |
| fi | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment