add session helper (#141)
All checks were successful
ci/woodpecker/push/docs Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful

### 📖 Summary

adds session helper:

- save session items
- restore a session
- show save session items
- reset a session file.

### 📑 Test Plan

 CI pipeline tests (Default)

### 💬 Details

_No response_

### 📚 Additional Notes

_No response_

Reviewed-on: #141
This commit is contained in:
OCram85 2024-11-21 15:44:11 +01:00
parent c319d8c1b5
commit b59945fc5b
5 changed files with 117 additions and 8 deletions

View File

@ -37,6 +37,11 @@ variables:
steps:
# TODO: Enable this in upcoming PRs.
#check-editorconfig:
# image: woodpeckerci/plugin-editorconfig-checker:0.2
# pull: true
test:
image: *build_plugin
settings:

View File

@ -180,7 +180,7 @@ This helps reducing the image size.
```
🧙 arkanum ✨🌌☄️💥 is used to install optional tools for developing in a
code-server container environment.
code-server container environment.
Syntax: arkanum <flags> COMMAND OPTION ARGUMENT
COMMAND
@ -192,7 +192,7 @@ This helps reducing the image size.
OPTION
config:
disable-motd Disables hint in new bash terminal.
install extensions Installs predefined recommended extensions.
install-extensions Installs predefined recommended extensions.
reset-codesettings Sets VS Code user setting with basic (Fira Code).
git:
@ -203,17 +203,24 @@ This helps reducing the image size.
install:
docker-cli Installs the latest docker-cli.
dotnet Installs latest LTS dotnet core sdk + runtime.
gitea Installs gitea tools like the changelog generator.
golang Installs golang 1.19.3.
gitea Installs gitea tools like changelog and tea.
golang Installs golang 1.21.5.
bun Installs latest bun version.
nodejs Installs latest NodeJs LTS version using Volta.
volta Installs Volta as NodeJS version manager.
powershell Installs latest PowerShell LTS version.
lazygit Installs latest Lazygit binary.
session:
save Adds items from the install command to the session config.
restore Restores the saved session.
reset Resets the session config.
show Show currently defined session content.
Example 1: arkanum git setup "my-name" "my-email"
Example 2: arkanum install golang
Example 3: arkanum config disable-motd
Example 4: arkanum session save lazygit powershell gitea
```
### 📝 Fira Code (NerdFont patched)

69
arkanum
View File

@ -37,9 +37,16 @@ function showHelp() {
powershell Installs latest PowerShell LTS version.
lazygit Installs latest Lazygit binary.
session:
save Adds items from the install command to the session config.
restore Restores the saved session.
reset Resets the session config.
show Show currently defined session content.
Example 1: arkanum git setup "my-name" "my-email"
Example 2: arkanum install golang
Example 3: arkanum config disable-motd
Example 4: arkanum session save lazygit powershell gitea
HELP
}
# endregion usage
@ -225,6 +232,7 @@ function installLazyGit() {
sudo rm -f /tmp/lazygit.tar.gz
rm -rf /tmp/lazygit
}
function instCodeExtension() {
say "Installing default extensions...." "Extension"
# Gitlens
@ -288,6 +296,48 @@ function setGitConfig() {
git config --list --global
}
function saveSession() {
SESSION_FILE="$HOME/arkanum-session"
if [[ $# -ge 3 ]]; then
for item in "${@:3}"; do
say "Adding '$item' to your session config" "saveSession"
echo "$item" | tee -a "$SESSION_FILE" > /dev/null
done
else
sayE "Unknown parameter count given" "saveSession"
exit 1
fi
}
function restoreSession() {
SESSION_FILE="$HOME/arkanum-session"
if [[ -e "$SESSION_FILE" ]]; then
while read item; do
say "Restoring '$item'..." "restoreSession"
arkanum install "$item"
done <"$SESSION_FILE"
say "Arkanum session restore completed. 🏁" "restoreSession"
else
sayE "There is no arkanum session!" "restoreSession"
exit 1
fi
}
function showSession() {
SESSION_FILE="$HOME/arkanum-session"
say "Trying to read your session config '$SESSION_FILE':" "showSession"
if [[ -e "$SESSION_FILE" ]]; then
cat "$SESSION_FILE"
else
sayE "There is no session defined!" "showSession"
fi
}
function resetSession() {
SESSION_FILE="$HOME/arkanum-session"
say "Deleting session file '$SESSION_FILE'..." "resetSession"
rm "$SESSION_FILE"
}
function main() {
if [[ "$#" == "0" ]]; then
showHelp
@ -347,6 +397,25 @@ function main() {
instGiteaTools
elif [[ "$2" == "lazygit" ]]; then
installLazyGit
else
sayE "Unknown option ($2) given for command 'install'!"
fi
elif [[ "$1" == "session" ]]; then
# session option
if [[ "$2" == "save" ]]; then
saveSession "$@"
exit 0
elif [[ "$2" == "restore" ]]; then
restoreSession
exit 0
elif [[ "$2" == "show" ]]; then
showSession
exit 0
elif [[ "$2" == "reset" ]]; then
resetSession
exit 0
else
sayE "Unknown option ($2) given for command 'session'!"
fi
else
sayE "Unknown parameter value given!($1)."

View File

@ -10,7 +10,7 @@ function _command_completions() {
case ${COMP_CWORD} in
1)
# shellcheck disable=2207,SC2086
COMPREPLY=($(compgen -W "config git install help" -- ${cur}))
COMPREPLY=($(compgen -W "config git install help session" -- ${cur}))
;;
2)
case ${prev} in
@ -26,6 +26,10 @@ function _command_completions() {
# shellcheck disable=2207,SC2086
COMPREPLY=($(compgen -W "docker-cli dotnet golang bun nodejs volta powershell gitea lazygit" -- ${cur}))
;;
session)
# shellcheck disable=2207,SC2086
COMPREPLY=($(compgen -W "save restore show reset" -- ${cur}))
;;
help)
;;
esac

View File

@ -3,8 +3,9 @@
## About
The `arkanum` container image includes the `arkanum-cli` to manage the current instance and be able to install
additional resources. To keep the base image as small as possible we decided not ot include all possible frameworks. This decision also helps to give the use the ability to manage the needed framework versions like for
NodeJS or Golang.
additional resources. To keep the base image as small as possible we decided not to include all possible frameworks.
With this approach the user can decide which frameworks are needed and install it by yourself. This avoids growing
the container image size.
For now the arkanum-cli is made with a simple bash script. But this could change whenever the complexity increases
significantly.
@ -14,7 +15,7 @@ significantly.
To use the cli just open a terminal and call the `arkanum` command. We also added a bash-completion
script for the cli.
<<< @/../arkanum#usage{35-37 bash:line-numbers}
<<< @/../arkanum#usage{19-22 bash:line-numbers}
The first thing you normally after starting your Arkanum instance is setting the git user and email:
@ -27,6 +28,29 @@ arkanum install golang
arkanum install nodejs
```
### Session Handling <Badge type="tip" text="^1.8.0" />
The session helper simplifies restoring your session after your instance was restarted. You can now save a global
session config which contains your needed frameworks installed by `arkanum install`. This wraps multiple install
calls and restores your session by running `arkanum session restore`.
For Example:
```bash
# Create a new session config by adding items
arkanum session save lazygit gitea golang
# Shows your saved session
arkanum session show
# Restore your session
arkanum session restore
# optionally reset / delete your session config
arkanum session reset
```
> [!WARNING]
> If your run `arkanum session save` multiple times and use the same arguments, they will also be added and
> installed multiple times!
## Referenced Source Files
::: code-group