Restrict tmux and desktop tools to Void hosts

This commit is contained in:
Fabio Scotto di Santolo
2026-03-31 19:00:15 +02:00
parent 99f1610a2c
commit 353ebb2624
177 changed files with 11 additions and 102 deletions

View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
declare -r CURRENT_DIR
# shellcheck source=/dev/null
source "$CURRENT_DIR/utils.sh"
is_authenticated() {
[[ $(bw status | jq '.status') != "\"unauthenticated\"" ]] && true
}
# Get bitwarden items
get_bw_items() {
local session="$1"
filter='map({ (.name|tostring): .login.password })|add'
if [[ -z "$session" ]]; then
bw list items | jq -r "$filter"
else
bw list items --session "$session" | jq -r "$filter"
fi
}
get_password() {
local items=$1
local key=$2
password=$(echo "$items" | jq ".\"$key\"")
echo "${password:1:-1}"
}
main() {
declare -A TMUX_OPTS=(
["@bw-session"]=$(get_tmux_option "@bw-session" "$BW_SESSION")
["@bw-copy-to-clipboard"]=$(get_tmux_option "@bw-copy-to-clipboard" "off")
)
is_authenticated
if [[ $? -eq 1 ]]; then
display_tmux_message "You are not logged in."
return 1
fi
items=$(get_bw_items "${TMUX_OPTS[@bw-session]}")
# Choice element
key=$(echo "$items" | jq --raw-output '.|keys[]' | fzf --no-multi) || return
password=$(get_password "$items" "$key")
if [[ "${TMUX_OPTS[@bw-copy-to-clipboard]}" == "on" ]]; then
cp_to_clipboard "$password"
else
# Send the password in the last pane.
tmux send-keys -t ! "$password"
fi
}
main "$@"

View File

@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# Copy text to the clipboard
cp_to_clipboard() {
if [[ "$(uname)" == "Darwin" ]] && is_binary_exist "pbcopy"; then
echo -n "$1" | pbcopy
elif [[ "$(uname)" == "Linux" ]] && is_binary_exist "wl-copy"; then
echo -n "$1" | wl-copy
elif [[ "$(uname)" == "Linux" ]] && is_binary_exist "xsel"; then
echo -n "$1" | xsel -b
elif [[ "$(uname)" == "Linux" ]] && is_binary_exist "xclip"; then
echo -n "$1" | xclip -i
else
return 1
fi
}
# Check if binary exist
is_binary_exist() {
local binary=$1
command -v "$binary" &> /dev/null
return $?
}
# Get tmux option
get_tmux_option() {
local option="$1"
local default_value="$2"
local option_value
option_value=$(tmux show-option -gqv "$option")
if [[ -z "$option_value" ]]; then
echo "$default_value"
else
echo "$option_value"
fi
}
# Display tmux message in status bar
display_tmux_message() {
local message=$1
tmux display-message "tmux-bitwarden: $message"
}