diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f53cc21711..997606833e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -19,11 +19,8 @@ // To access grafana "appPort": "3000:3000", - // 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..b8fee321a4 --- /dev/null +++ b/.devcontainer/postAttachCommand.sh @@ -0,0 +1,35 @@ +#!/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..." + +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"