From f2f4c8f303dcf8b70944a677c622db5dcb8361fb Mon Sep 17 00:00:00 2001 From: ykadowak Date: Tue, 30 Jan 2024 04:05:29 +0000 Subject: [PATCH 1/2] Refactor postAttachCommand --- .devcontainer/devcontainer.json | 8 ++++---- .devcontainer/postAttachCommand.sh | 32 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 .devcontainer/postAttachCommand.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f53cc21711..9b6d689a3f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -19,11 +19,11 @@ // To access grafana "appPort": "3000:3000", + // define named volume to store zsh history file + "mounts": ["source=zshhistory-named-volume,target=/commandhistory,type=volume"], + // Persist zsh history settings below // overwrite HISTFILE to store history file in the named volume defined below // also setting INC_APPEND_HISTORY to immediately flush command history to the file to keep history when rebuilding the devcontainer - "postStartCommand": "echo 'export HISTFILE=/commandhistory/.zsh_history' >> /root/.zshrc && echo 'setopt INC_APPEND_HISTORY' >> /root/.zshrc", - // define named volume to store zsh history file - "mounts": ["source=zshhistory-named-volume,target=/commandhistory,type=volume"], - "postAttachCommand": "mkdir -p /etc/server && ln -s $(pwd)/cmd/agent/core/ngt/sample.yaml /etc/server/config.yaml" + "postAttachCommand": ["/bin/bash", ".devcontainer/postAttachCommand.sh"] } diff --git a/.devcontainer/postAttachCommand.sh b/.devcontainer/postAttachCommand.sh new file mode 100644 index 0000000000..52121eb0a4 --- /dev/null +++ b/.devcontainer/postAttachCommand.sh @@ -0,0 +1,32 @@ +#!/bin/bash -eu +# +# This script is executed as postAttachCommand in devcontainer.json +# + +echo "creating symbolic link of config ZSHRC..." + +LINK_TARGET="$(pwd)/cmd/agent/core/ngt/sample.yaml" +LINK_SRC="/etc/server/config.yaml" + +mkdir -p /etc/server + +if [ ! -e "$LINK_SRC" ]; then + ln -s "$LINK_TARGET" "$LINK_SRC" + echo "created symbolic link: $LINK_SRC -> $LINK_TARGET" +else + echo "$LINK_SRC already exists" +fi + + +echo "adding history setting to .zshrc..." + +LINE1="export HISTFILE=/commandhistory/.zsh_history" +LINE2="setopt INC_APPEND_HISTORY" + +ZSHRC="/root/.zshrc" + +# write only if those lines don't exist +grep -qxF "$LINE1" "$ZSHRC" || echo "$LINE1" >> "$ZSHRC" +grep -qxF "$LINE2" "$ZSHRC" || echo "$LINE2" >> "$ZSHRC" + +echo "added history setting to .zshrc" From af09336bb22d46a30463ff85434cc3227acfd6c0 Mon Sep 17 00:00:00 2001 From: ykadowak Date: Tue, 30 Jan 2024 04:21:54 +0000 Subject: [PATCH 2/2] Refactor comment --- .devcontainer/devcontainer.json | 3 --- .devcontainer/postAttachCommand.sh | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9b6d689a3f..997606833e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -22,8 +22,5 @@ // define named volume to store zsh history file "mounts": ["source=zshhistory-named-volume,target=/commandhistory,type=volume"], - // Persist zsh history settings below - // overwrite HISTFILE to store history file in the named volume defined below - // also setting INC_APPEND_HISTORY to immediately flush command history to the file to keep history when rebuilding the devcontainer "postAttachCommand": ["/bin/bash", ".devcontainer/postAttachCommand.sh"] } diff --git a/.devcontainer/postAttachCommand.sh b/.devcontainer/postAttachCommand.sh index 52121eb0a4..b8fee321a4 100644 --- a/.devcontainer/postAttachCommand.sh +++ b/.devcontainer/postAttachCommand.sh @@ -1,6 +1,9 @@ #!/bin/bash -eu # # This script is executed as postAttachCommand in devcontainer.json +# This script does... +# - create symbolic link of config.yaml for easier development +# - add command history setting to .zshrc to persist history # echo "creating symbolic link of config ZSHRC..."