[gopass] Add reading options from config file

File can be used to alter the functions of rofi-gopass.
This commit is contained in:
Marty Oehme 2020-05-15 21:12:13 +02:00
parent 87031b8ce7
commit 75397a0bb2
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A
2 changed files with 47 additions and 16 deletions

View file

@ -26,6 +26,8 @@
# default key bindings # default key bindings
# Automatically enter username and password # Automatically enter username and password
# KEY_AUTOFILL="Return" # KEY_AUTOFILL="Return"
# Open entry
# KEY_OPEN_ENTRY
# Automatically enter username only # Automatically enter username only
# KEY_FILL_USER="Alt+u" # KEY_FILL_USER="Alt+u"
# Add username to clipboard # Add username to clipboard
@ -47,6 +49,9 @@
# Will go through names in descending precedence # Will go through names in descending precedence
# GOPASS_USERNAME_FIELD="username user login" # GOPASS_USERNAME_FIELD="username user login"
# The location of the rofi-gopass config file
# ROFI_PASS_CONFIGURATION_FILE="~/.config/rofi-gopass"
# rofi wrapper. Add custom settings here. # rofi wrapper. Add custom settings here.
_rofi() { _rofi() {
# TODO add check for dmenu # TODO add check for dmenu
@ -54,6 +59,25 @@ _rofi() {
rofi -dmenu -no-auto-select -i "$@" -p "Entry" rofi -dmenu -no-auto-select -i "$@" -p "Entry"
} }
# read config file
get_config_file() {
local locations=("$ROFI_PASS_CONFIGURATION_FILE"
"${XDG_CONFIG_HOME:-$HOME/.config}/rofi-gopass/rofi-gopass.conf"
"$HOME/.rofi-gopass.conf"
"/etc/rofi-gopass.conf")
# return the first config file with a valid path
for config in "${locations[@]}"; do
if [[ -n "$config" && -f "$config" ]]; then
# we only source config values, don't complain
# shellcheck disable=SC1090
source "$config"
echo "sourced config"
return
fi
done
}
# exit on escape pressed # exit on escape pressed
# rofi returns exit code 1 on esc # rofi returns exit code 1 on esc
exit_check() { exit_check() {
@ -198,7 +222,7 @@ main() {
local k_clip_user="${KEY_CLIP_USER:-Ctrl+Alt+u}" local k_clip_user="${KEY_CLIP_USER:-Ctrl+Alt+u}"
local k_fill_pass="${KEY_FILL_PASS:-Alt+p}" local k_fill_pass="${KEY_FILL_PASS:-Alt+p}"
local k_clip_pass="${KEY_CLIP_PASS:-Ctrl+Alt+p}" local k_clip_pass="${KEY_CLIP_PASS:-Ctrl+Alt+p}"
local k_submenu="${KEY_CLIP_PASS:-Alt+Return}" local k_submenu="${KEY_OPEN_ENTRY:-Alt+Return}"
entry="$( entry="$(
list_passwords | list_passwords |
@ -242,4 +266,5 @@ main() {
esac esac
} }
get_config_file
main main

View file

@ -12,25 +12,31 @@ To make accessing secrets easy, it uses the `rofi-gopass` script, which creates
![rofi-gopass demonstration](.assets/gopass/rofi-menu.gif) ![rofi-gopass demonstration](.assets/gopass/rofi-menu.gif)
There are several keybindings available, to either fill or copy to clipboard the username, password, or open the full view to an individual entry. For every send to clipboard action, the clipboard will be automatically cleared after the time specified in your gopass settings. There are several keybindings available, to either fill or copy to clipboard the username, password, or open the full view to an individual entry. For every send to clipboard action, the clipboard will be automatically cleared after the time specified in your gopass settings. For auto-filling to work correctly, the username field will (by default) have to be highlighted.
| keybinding | function | | keybinding | function | setting name |
| -------- | -------- | | -------- | -------- | ---------- |
| Return | Auto-fill username & password | | Return | Auto-fill username & password | KEY_AUTOFILL |
| Alt+Return | Open individual entry | | Alt+Return | Open individual entry | KEY_OPEN_ENTRY |
| Alt+u | Auto-fill username | | Alt+u | Auto-fill username | KEY_FILL_USER |
| Alt+p | Auto-fill password | | Alt+p | Auto-fill password | KEY_FILL_PASS |
| Ctrl+Alt+u | Send username to clipboard | | Ctrl+Alt+u | Send username to clipboard | KEY_CLIP_USER |
| Ctrl+Alt+p | Send password to clipboard | | Ctrl+Alt+p | Send password to clipboard | KEY_CLIP_PASS |
| Return | Auto-fill selected field (from opened entry) | | Return | Auto-fill selected field (from opened entry) | KEY_ENTRYMENU_FILL |
| Alt+Return | Send selected field to clipboard (from opened entry) | | Alt+Return | Send selected field to clipboard (from opened entry) | KEY_ENTRYMENU_CLIP |
| Alt+BackSpace | Close individual entry, return to overview | | Alt+BackSpace | Close individual entry, return to overview | KEY_ENTRYMENU_QUIT |
These keys can be reconfigured at the top of the script file. These keys, as well as the additional configuration can be changed by setting the corresponding environment variable, through a configuration file, or at the top of the script file itself. The script tries to follow xdg-specification, meaning it looks for a configuration file in the following directories (in descending order):
For auto-filling to work, the username field will (by default) have to be highlighted. * `XDG_CONFIG_HOME/rofi-gopass/rofi-gopass.conf`
* `~/.config/rofi-gopass/rofi-gopass.conf`
* `~/.rofi-gopass.conf`
* `/etc/rofi-gopass.conf`
Additional configuration at the top of the script file: or, alternatively, a custom directory if the `ROFI_PASS_CONFIGURATION_FILE` variable points to a configuration file.
Additional configuration options:
* `BACKEND` * `BACKEND`
:sets the auto-filling tool used, only tested with `xdotool` currently. :sets the auto-filling tool used, only tested with `xdotool` currently.