From cd81484dc1ed5268b7de82ce0520cef23868e559 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sun, 1 May 2022 19:43:56 +0300
Subject: [PATCH] wb: Some more small fixes.

- Fix usage message.
- Better not_in_toolbox function and usage. The function now checks if
  in a Toolbox container and fails accordingly. All of the usage cases
were like that so now calling the function is a little cleaner.
- Fixup for the last commit. If the Toolbox container was just created,
  it's not running and then `podman exec` fails. Running a simple
`toolbox run true` fixes this.
---
 Documents/bin/wb | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/Documents/bin/wb b/Documents/bin/wb
index e38220b..81b3602 100755
--- a/Documents/bin/wb
+++ b/Documents/bin/wb
@@ -7,7 +7,7 @@ TMUX_SOCKET='workbench'
 DEFAULT_SESSION='workbench'
 
 usage() {
-    echo "$(basename "$0"): [-h|--help] [-u|--update] [-d|--dry-update] [-l|--list] [-k|--kill] [-s|--kill-server] [-i|--in-workbench] [SESSION_NAME]"
+    echo "Usage: $(basename "$0") [-h|--help] [-u|--update] [-d|--dry-update] [-l|--list] [-k|--kill] [-s|--kill-server] [-i|--in-workbench] [SESSION_NAME]"
 }
 
 fail() {
@@ -16,7 +16,10 @@ fail() {
 }
 
 not_from_toolbox() {
-    fail 'This command cannot run from within the workbench container.'
+    if in_toolbox
+    then
+        fail 'This command cannot run from within the workbench container.'
+    fi
 }
 
 command -v toolbox >/dev/null || fail 'Toolbox is not installed.'
@@ -79,26 +82,21 @@ kill_tmux() {
 }
 
 kill_server() {
-    if in_toolbox
-    then
-        not_from_toolbox
-    fi
+    not_from_toolbox
     kill_tmux
     toolbox rm -f "$CONTAINER"
 }
 
 update() {
-    if in_toolbox
-    then
-        not_from_toolbox
-    fi
+    not_from_toolbox
     if ! is_latest
     then
         kill_server
         podman image prune --filter 'label=com.github.containers.toolbox=true' --force >/dev/null
         toolbox create --image "$IMAGE"
     fi
-    podman exec -it -w "$HOME" -u "$(whoami)" "$CONTAINER" git pull
+    toolbox run --container "$CONTAINER" -- true
+    podman exec -it -w "$HOME" -u "$(whoami)" "$CONTAINER" git Pull
 }
 
 dry_update() {
-- 
GitLab