Open
Description
Instead of keepassxc-cli <sub-command> [options] database <arg>
, have dataset set either by using a default path or an environment variable so it become keepassxc-cli <subcommand> [options] <arg>
.
I am using this bash script to achieve this:
#!/bin/bash
kp() {
DATABASE="/path/to/database"
subcommand="$1"
shift
options=()
while [[ $# -gt 1 ]]; do
options+=("$1")
shift
done
term="$1"
keepassxc-cli "$subcommand" "${options[@]}" "$DATABASE" "$term"
}
kp "$@"
This script is simple, but it's not complete. For example, it doesn't handle all corner cases like keepassxc-cli ls -h properly. Does keepassxc-cli have a mechanism to basically not give the dataset and fall back to a default one or an environment variable? I did search the manual but couldn't find a relevant piece.
Activity
droidmonkey commentedon Apr 17, 2024
See here for a previous discussion: #6225
I am not against querying an env var if the database is not supplied on the command line itself. Probably something like
KPXC_CLI_DBFILE
sadid commentedon Apr 17, 2024
First of all, Thanks for the awesome app!
Yes I think env var helps a lot. Alternatively, checking for a default path (like ~/.DB.kdbx) when the databse have not provided in the command line might help.
Just for sake of compelteness, I improved my wrapper and now it cover all my use cases and I think more versatile than the #6225
salazarp commentedon Nov 3, 2024
Would it make sense to give the database location its own option (e.g. "-d") rather than make it positional?
I could then do a quick alias:
function kp(){ keepassxc-cli -d "${KDBX}" "$@"; }
...and I could happily do
kp ls
orkp show -s mygroup
, or anything else.As it stands currently, I can naively try this:
function kp(){ keepassxc-cli "$@" "$KDBX"; }
...which will work well for
kp -l
but not forkp -l $KBDX mygroup
.The problem is the alias/function/script needs to parse how many arguments are there before the database path in every command, and it all gets cumbersome quickly.
Like all the others, awed and ever grateful for the work. 🫶