/
/
/
1
2
3
4docker-nets() { docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }} {{range .NetworkSettings.Networks}} {{.IPAddress}}{{end}}' | sed 's#^/##'; }
5docker-enter() { docker exec -e COLORFGBG -e TERM -ti -u root $1 bash -li ; }
6
7restic-list() { restic snapshots --json | jq -r '.[].paths[]' | sort -u ; }
8bgl-git-check-latest() { git submodule foreach --recursive 'case "$(echo $name | cut -c1-3)" in "bgl"|"prj"|"spc") git fetch && git checkout "$(git symbolic-ref refs/remotes/origin/HEAD | cut -d'/' -f4)" && git clean -ffxd && git pull && git submodule update --init --recursive ;; *) echo "No bgl repo, leaving as is!" ;; esac' ; }
9bglCheckoutTag() { git submodule foreach --recursive 'case "$(echo $name | cut -c1-3)" in "bgl"|"prj") git fetch && if [ "$(git tag -l $1)" ]; then git checkout $1 ; else git checkout "$(git describe --tags $(git rev-list --tags --max-count=1))"; fi && git clean -ffxd && git submodule update --init --recursive ;; *) echo "No bgl repo, leaving as is!" ;; esac' ; }
10bglGetTag() { if [ "$(git ls-remote $2 | grep tags | rev | cut -d '/' -f 1 | rev | grep $1)" ]; then echo "$1"; else echo "$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' $2 | rev | cut -d '/' -f 1 | rev)"; fi ; }
11
12run_command_on_bgl_submodules() { command_to_run="$*"; git submodule foreach --quiet --recursive 'case "$name" in bgl*) '"$command_to_run"' ;; *) ;; esac'; }
13
14bgl-git-cmd() { prefix="$1"; shift; command_to_run="$*"; git submodule foreach --quiet --recursive 'case "$name" in '"$prefix"'*) '"$command_to_run"' ;; *) ;; esac'; }
15bgl-git-cmd-all() { command_to_run="$*"; git submodule foreach --quiet --recursive 'case "$name" in bgl*|prj*|spc*) '"$command_to_run"' ;; esac'; }
16bgl-git-check-latest() { git submodule foreach --recursive 'case "$(echo $name | cut -c1-3)" in "bgl"|"prj"|"spc") git fetch && git checkout "$(git symbolic-ref refs/remotes/origin/HEAD | cut -d'/' -f4)" && git clean -ffxd && git pull && git submodule update --init --recursive ;; *) echo "No bgl repo, leaving as is!" ;; esac' ; }
17bgl-git-check-tag() { git submodule foreach --recursive 'case "$(echo $name | cut -c1-3)" in "bgl"|"prj"|"spc") git fetch && if [ "$(git tag -l $1)" ]; then git checkout $1 ; else git checkout "$(git describe --tags $(git rev-list --tags --max-count=1))"; fi && git clean -ffxd && git submodule update --init --recursive ;; *) echo "No bgl repo, leaving as is!" ;; esac' ; }
18bgl-git-get-tag() { tag="$1"; if git tag -l | grep -q "^$tag$"; then echo "$tag"; else latest_tag=$(git tag -l --sort=-v:refname | head -n1); if [ -z "$latest_tag" ]; then echo "$(git symbolic-ref --short HEAD)"; else echo "$latest_tag"; fi; fi; }
19bgl-git-commit() { [ -z "$1" ] && { echo "Usage: gcb MESSAGE"; return 1; } ; branch=$(git symbolic-ref --short HEAD); ticket=$(echo "$branch" | grep -o "AMR-[0-9]\+"); git commit -m "$ticket: $1"; }
20
21bgl-git-help() {
22 cat <<EOF
23bgl-git-cmd() {
24 Usage: bgl-git-cmd PREFIX COMMAND [ARGS...]
25
26 Parameters:
27 PREFIX The prefix to filter submodules (e.g., 'bgl').
28 COMMAND The git command to execute on matching submodules.
29 [ARGS...] Arguments for the git command.
30
31 Description:
32 Executes the specified git COMMAND on all submodules whose names start with the given PREFIX.
33 Only submodules matching the PREFIX are affected.
34}
35
36bgl-git-cmd-all() {
37 Usage: bgl-git-cmd-all COMMAND [ARGS...]
38
39 Parameters:
40 COMMAND The git command to execute.
41 [ARGS...] Arguments for the git command.
42
43 Description:
44 Executes the specified git COMMAND on all submodules whose names start with 'bgl', 'prj', or 'spc'.
45 This command affects all submodules matching these prefixes.
46}
47
48bgl-git-check-latest() {
49 Usage: bgl-git-check-latest
50
51 Description:
52 For each submodule with names starting with 'bgl', 'prj', or 'spc', performs a series of git operations:
53 - Fetches updates
54 - Checks out the default branch
55 - Cleans untracked files and directories
56 - Pulls the latest changes
57 - Updates submodules
58
59 If a submodule does not match the prefix, it will display "No bgl repo, leaving as is!".
60}
61
62bgl-git-check-tag() {
63 Usage: bgl-git-check-tag TAG
64
65 Parameters:
66 TAG The tag to check out.
67
68 Description:
69 For each submodule with names starting with 'bgl', 'prj', or 'spc', performs the following:
70 - Fetches updates
71 - Checks if the specified TAG exists and checks it out
72 - If TAG does not exist, checks out the most recent tag
73 - Cleans untracked files and directories
74 - Updates submodules
75
76 If a submodule does not match the prefix, it will display "No bgl repo, leaving as is!".
77}
78
79bgl-git-get-tag() {
80 Usage: bgl-git-get-tag TAG
81
82 Parameters:
83 TAG The tag to check for.
84
85 Description:
86 Prints the TAG if it exists in the current repository.
87 If TAG does not exist, prints the latest tag in the repository.
88 If no tags are present, prints the name of the current branch.
89}
90
91bgl-git-commit() {
92 Usage: bgl-git-commit MESSAGE
93
94 Parameters:
95 MESSAGE The commit message. The function will prepend the current branch name to the message.
96
97 Description:
98 Commits changes with a message that includes the current branch name prefixed with "AMR-".
99}
100EOF
101}
102
103
104bgl-docker-restart() { docker compose down -f /opt/bgl/docker/docker-compose.yaml && docker compose up -d -f /opt/bgl/docker/docker-compose.yaml ; }
105bgl-docker-minator() { docker exec -d -e COLORFGBG -e DISPLAY=$DISPLAY -t -u bgldev "$1" terminator & disown ; }
106bgl-docker-enter() { docker exec -e COLORFGBG -e TERM -e DISPLAY=$DISPLAY -ti -u bgldev $1 bash -li ; }
107
108bgl-docker-help() {
109 cat <<EOF
110bgl-docker-restart() {
111 Usage: bgl-docker-restart
112
113 Description:
114 Restarts Docker containers defined in the /opt/bgl/docker/docker-compose.yaml file.
115 Stops the containers first, then starts them again in detached mode.
116}
117
118bgl-docker-minator() {
119 Usage: bgl-docker-minator CONTAINER
120
121 Parameters:
122 CONTAINER The name or ID of the Docker container to run Terminator in.
123
124 Description:
125 Executes the Terminator terminal emulator inside the specified Docker container.
126 Sets environment variables COLORFGBG and DISPLAY, and runs Terminator in detached mode.
127}
128
129bgl-docker-enter() {
130 Usage: bgl-docker-enter CONTAINER
131
132 Parameters:
133 CONTAINER The name or ID of the Docker container to enter.
134
135 Description:
136 Opens a bash shell inside the specified Docker container with interactive and login options.
137 Sets environment variables COLORFGBG, TERM, and DISPLAY for the shell session.
138}
139EOF
140}
141