Open sadid opened 4 months ago
See here for a previous discussion: https://github.com/keepassxreboot/keepassxc/issues/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
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
#!/bin/bash
function kp_wrapper() {
sub_command="$1"
shift
local DB="$HOME/.DB.kdbx"
if [[ $# -le 1 ]]; then
echo "keepassxc-cli $sub_command $@ $DB"
keepassxc-cli "$sub_command" "$@" "$DB"
return
fi
local last_arg="${@: -1}"
local args=("${@: 1:$(($#-1))}")
if [[ $last_arg == -* ]]; then
args+=("$DB")
else
args=("${args[@]}" "$DB" "$last_arg")
fi
echo "keepassxc-cli $sub_command ${args[@]}"
keepassxc-cli "$sub_command" "${args[@]}"
}
kp_wrapper "$@"
Instead of
keepassxc-cli <sub-command> [options] database <arg>
, have dataset set either by using a default path or an environment variable so it becomekeepassxc-cli <subcommand> [options] <arg>
.I am using this bash script to achieve this:
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.