From 3febd5073ef58744ac9d3614087d30f59111a7e4 Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Fri, 17 Oct 2025 09:26:12 +0200 Subject: [PATCH] feat(dotenv): add KeePass support and rename dotenv commands for clarity --- README.md | 30 +++++++++++++++++++--- bin/load-dotenv-from-keepass | 11 ++++++++ bin/{load-dotenv => load-dotenv-from-pass} | 2 +- bin/save-dotenv-to-keepass | 19 ++++++++++++++ bin/{save-dotenv => save-dotenv-to-pass} | 2 +- 5 files changed, 58 insertions(+), 6 deletions(-) create mode 100755 bin/load-dotenv-from-keepass rename bin/{load-dotenv => load-dotenv-from-pass} (85%) mode change 100644 => 100755 create mode 100755 bin/save-dotenv-to-keepass rename bin/{save-dotenv => save-dotenv-to-pass} (85%) mode change 100644 => 100755 diff --git a/README.md b/README.md index e4c10c2..9314bcd 100644 --- a/README.md +++ b/README.md @@ -827,16 +827,38 @@ Set path to pass entry. PASS_ENTRY=$(echo "env/${PWD##*/}" | tr '[:upper:]' '[:lower:]') ``` -#### save-dotenv +#### save-dotenv-to-pass ```bash - printf "$COLUMN" "save-dotenv" "" "Store content of .env in pass entry." + printf "$COLUMN" "save-dotenv-to-pass" "" "Store content of .env in pass entry." ``` -#### load-dotenv +#### load-dotenv=from-pass ```bash - printf "$COLUMN" "load-dotenv" "" "Restore content to .env from pass entry." + printf "$COLUMN" "load-dotenv=from-pass" "" "Restore content to .env from pass entry." +``` + +### KeePass + +Set path to KeePass database and entry. + +```bash +KEEPASS_DATABASE_FILE="/path/to/database.kdbx" +KEEPASS_DATABASE_KEY_FILE="/path/to/keepass.key" +KEEPASS_ENTRY=$(echo "env/${PWD##*/}" | tr '[:upper:]' '[:lower:]') +``` + +#### save-dotenv-to-keepass + +```bash + printf "$COLUMN" "save-dotenv-to-keepass" "" "Store content of .env in KeePass entry." +``` + +#### load-dotenv-from-keepass + +```bash + printf "$COLUMN" "load-dotenv-from-keepass" "" "Restore content to .env from KeePass entry." ``` ### Docker diff --git a/bin/load-dotenv-from-keepass b/bin/load-dotenv-from-keepass new file mode 100755 index 0000000..965d23e --- /dev/null +++ b/bin/load-dotenv-from-keepass @@ -0,0 +1,11 @@ +#!/bin/bash + +function load-dotenv-from-keepass { + echo "Restore .env file from keepassxc: $KEEPASS_ENTRY" + keepassxc-cli attachment-export \ + --key-file "$KEEPASS_DATABASE_KEY_FILE" \ + "$KEEPASS_DATABASE_FILE" \ + "$KEEPASS_ENTRY" \ + ".env" \ + ".env" +} \ No newline at end of file diff --git a/bin/load-dotenv b/bin/load-dotenv-from-pass old mode 100644 new mode 100755 similarity index 85% rename from bin/load-dotenv rename to bin/load-dotenv-from-pass index 6c4bf66..1a893f8 --- a/bin/load-dotenv +++ b/bin/load-dotenv-from-pass @@ -1,6 +1,6 @@ #!/bin/bash -function load-dotenv() { +function load-dotenv-from-pass() { if pass find "$PASS_ENTRY" >/dev/null; then echo "Restore .env file from pass: $PASS_ENTRY" pass show "$PASS_ENTRY" > .env diff --git a/bin/save-dotenv-to-keepass b/bin/save-dotenv-to-keepass new file mode 100755 index 0000000..0d01d75 --- /dev/null +++ b/bin/save-dotenv-to-keepass @@ -0,0 +1,19 @@ +#!/bin/bash + +function save-dotenv-to-keepass { + if [ -f .env ]; then + echo "Store .env file in keepassxc: $KEEPASS_ENTRY" + keepassxc-cli add \ + --key-file "$KEEPASS_DATABASE_KEY_FILE" \ + "$KEEPASS_DATABASE_FILE" \ + "$KEEPASS_ENTRY" + keepassxc-cli attachment-import \ + --key-file "$KEEPASS_DATABASE_KEY_FILE" \ + "$KEEPASS_DATABASE_FILE" \ + "$KEEPASS_ENTRY" \ + ".env" \ + ".env" + else + echo "No .env file found." + fi +} diff --git a/bin/save-dotenv b/bin/save-dotenv-to-pass old mode 100644 new mode 100755 similarity index 85% rename from bin/save-dotenv rename to bin/save-dotenv-to-pass index d12b7dc..3d3a8c5 --- a/bin/save-dotenv +++ b/bin/save-dotenv-to-pass @@ -1,6 +1,6 @@ #!/bin/bash -function save-dotenv() { +function save-dotenv-to-pass() { if [ -f .env ]; then echo "Store .env file in pass: $PASS_ENTRY" cat .env | pass insert -m -f "$PASS_ENTRY"