From 400650504b0ffe5d68bcd6be376ee152d7b43e1f Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Tue, 25 Oct 2022 18:48:16 -0400 Subject: [PATCH 1/2] bashrc: Add SSH_AUTH_SOCK for gpg-agent --- bash/.bashrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bash/.bashrc b/bash/.bashrc index 1436d63..3da0702 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -93,3 +93,6 @@ export PATH="$PATH:~/.local/bin" # Password Store export PASSWORD_STORE_ENABLE_EXTENSIONS=true + +# Use gpg-agent-ssh +export SSH_AUTH_SOCK=/run/user/1000/gnupg/S.gpg-agent.ssh From 293826355f36960aa78b61270ea4c045b1912796 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Tue, 25 Oct 2022 20:53:02 -0400 Subject: [PATCH 2/2] bashrc: Support filtering tailscale nodes --- bash/.bashrc | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/bash/.bashrc b/bash/.bashrc index 3da0702..964d703 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -47,27 +47,40 @@ function sshunlock() { # Show a menu of all known Tailscale nodes for the user to select from function tsselect() { local items=() - local hostnames=() while read -r line; do [ -z "$line" ] && continue [[ "$line" =~ ^\# ]] && continue local name=$(echo "$line" | awk '{ print $2 }') - local ip=$(echo "$line" | awk '{ print $1 }') - items+=("$name ($ip)") - hostnames+=("$name") + items+=("$name") done <<< $(tailscale status --self=false | sort -k 2) _COLUMNS=$COLUMNS # Force options to display in one column COLUMNS=80 - select item in "${items[@]}" Cancel; do - if [ $REPLY -eq ${#items[@]} ]; then - echo "" - fi - echo ${hostnames[$((REPLY - 1))]} - break; + while [ "${#items[@]}" -gt 1 ]; do + select item in "${items[@]}" Cancel; do + if [[ "$REPLY" =~ ^[0-9]+$ ]]; then + # Number selections -- break immediately + if [ $REPLY -eq $((1 + ${#items[@]})) ]; then + items=("") + break + elif [ $REPLY -le ${#items[@]} ]; then + items=("${items[$((REPLY - 1))]}") + break + fi + fi + # Not a number selection -- filter the items + items=($(printf "%s\n" "${items[@]}" | grep -E "^$REPLY")) + break + done done COLUMNS=$_COLUMNS + if ! ([[ "$REPLY" =~ ^[0-9]+$ ]] || [ "$REPLY" == "${items[0]}" ]); then + echo -n "${items[0]}? (y/n) " >&2 + read yn + [ "$yn" == "y" ] || return 1 + fi + echo "${items[0]}" } # SSH shorthands, same as before but for tailscale nodes