From 76819f7b9530864c11905882393f658f245b8b7d Mon Sep 17 00:00:00 2001 From: Flo Date: Sat, 21 Dec 2024 03:19:46 +0100 Subject: [PATCH] aliases --- .gitignore | 2 +- .profile | 22 ++++++++++++++++++---- bin/denv | 2 +- bin/drun | 6 +++++- init | 4 ++++ script/update_profile | 3 ++- script/write_aliases | 24 ++++++++++++++++++++++++ up | 7 ++++++- 8 files changed, 61 insertions(+), 9 deletions(-) create mode 100755 script/write_aliases diff --git a/.gitignore b/.gitignore index 9342acd..93c3bdb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ systems/* var/ -.alias +.aliases .systems \ No newline at end of file diff --git a/.profile b/.profile index 049dcfd..151013d 100644 --- a/.profile +++ b/.profile @@ -1,11 +1,25 @@ -# GIT branch in bash START +# bin +. $DEV_ENV_PATH/bin/denv +. $DEV_ENV_PATH/bin/dcom +. $DEV_ENV_PATH/bin/drun +. $DEV_ENV_PATH/bin/git +# /bin + +# alias +if [ -f "$DEV_ENV_PATH/.aliases" ]; then + . "$DEV_ENV_PATH/.aliases" +fi +# /alias + +# GIT branch in bash parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ ' -# GIT branch in bash END +# /GIT branch in bash -# SSH Setup START + +# SSH SSH_ENV="$HOME/.ssh/agent-environment" function start_agent { echo "Initialising new SSH agent..." @@ -26,4 +40,4 @@ if [ -f "$SSH_ENV" ]; then else start_agent fi -# SSH Setup END \ No newline at end of file +# /SSH \ No newline at end of file diff --git a/bin/denv b/bin/denv index 5d9e5e6..de7e322 100644 --- a/bin/denv +++ b/bin/denv @@ -2,7 +2,7 @@ ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../" &> /dev/null && pwd ) denv() { - if [ ! -z $1 ] then + if [ ! -z $1 ] ; then $ENV_DIR/$1 else cd $ENV_DIR diff --git a/bin/drun b/bin/drun index e4b806d..8a3c159 100644 --- a/bin/drun +++ b/bin/drun @@ -16,7 +16,11 @@ drun() { return 1 fi - docker exec -it "$CONTAINER_ID" $COMMAND + if [[ -t 0 && -t 1 ]]; then + docker exec -it "$CONTAINER_ID" $COMMAND + else + docker exec "$CONTAINER_ID" $COMMAND + fi } _drun_completion() { diff --git a/init b/init index 8963303..a327695 100755 --- a/init +++ b/init @@ -9,6 +9,10 @@ then denv_info_msg "[dev-env]: docker-compose.yml created" fi +# Update .aliases +$ENV_DIR/script/write_aliases +echo "" + # Update .profile $ENV_DIR/script/update_profile echo "" diff --git a/script/update_profile b/script/update_profile index 817633c..3bf3eb8 100755 --- a/script/update_profile +++ b/script/update_profile @@ -30,7 +30,8 @@ else denv_echo_msg "[dev-env]: Section does not exists. Adding contents..." fi +ENV_DIR_STRING="#DEV-ENV\nDEV_ENV_PATH=$ENV_DIR\n#DEV-ENV" # Add contents -echo -e "\n$START_MARKER\n$TEMPLATE_CONTENT\n$END_MARKER" >> "$PROFILE_FILE" +echo -e "\n$START_MARKER\n$ENV_DIR_STRING\n$TEMPLATE_CONTENT\n$END_MARKER" >> "$PROFILE_FILE" denv_success_msg "[dev-env]: Successfully updated $PROFILE_FILE" diff --git a/script/write_aliases b/script/write_aliases new file mode 100755 index 0000000..07c4990 --- /dev/null +++ b/script/write_aliases @@ -0,0 +1,24 @@ +#!/bin/bash +ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd ) +CONFIG_FILE="$ENV_DIR/.systems" +source $ENV_DIR/bin/denv_msg + +# Check if .systems configuration exists +if [ ! -f "$CONFIG_FILE" ]; then + denv_error_msg "$CONFIG_FILE not found." + exit 1 +fi + +echo "" > "$ENV_DIR/.aliases" + +# Iterate through all lines in .systems configuration +while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do + # Skip comments and emtpy lines + if [[ "$IDENTIFIER" =~ ^#.* ]] || [ -z "$IDENTIFIER" ]; then + continue + fi + + DIRECTORY="systems/$DIRECTORY" + echo "alias goto-$IDENTIFIER='cd \$DEV_ENV_PATH/$DIRECTORY'" >> "$ENV_DIR/.aliases" + +done < "$CONFIG_FILE" diff --git a/up b/up index 278225c..d08bcce 100755 --- a/up +++ b/up @@ -7,4 +7,9 @@ denv_info_msg "Executing up -d dev-env" docker compose -f "$ENV_DIR/docker/docker-compose.yml" up -d echo "" -$ENV_DIR/script/foreachSystem/dcom up -d \ No newline at end of file +$ENV_DIR/script/foreachSystem/dcom up -d + +if [[ ! -f "$ENV_DIR/var/.firstRun" ]] ; then + $ENV_DIR/script/foreachSystem/runScript firstRun + touch "$ENV_DIR/var/.firstRun" +fi \ No newline at end of file