Compare commits
2 commits
93d8553a61
...
293826355f
Author | SHA1 | Date | |
---|---|---|---|
293826355f | |||
400650504b |
1 changed files with 26 additions and 10 deletions
36
bash/.bashrc
36
bash/.bashrc
|
@ -47,27 +47,40 @@ function sshunlock() {
|
||||||
# Show a menu of all known Tailscale nodes for the user to select from
|
# Show a menu of all known Tailscale nodes for the user to select from
|
||||||
function tsselect() {
|
function tsselect() {
|
||||||
local items=()
|
local items=()
|
||||||
local hostnames=()
|
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
[ -z "$line" ] && continue
|
[ -z "$line" ] && continue
|
||||||
[[ "$line" =~ ^\# ]] && continue
|
[[ "$line" =~ ^\# ]] && continue
|
||||||
local name=$(echo "$line" | awk '{ print $2 }')
|
local name=$(echo "$line" | awk '{ print $2 }')
|
||||||
local ip=$(echo "$line" | awk '{ print $1 }')
|
items+=("$name")
|
||||||
items+=("$name ($ip)")
|
|
||||||
hostnames+=("$name")
|
|
||||||
done <<< $(tailscale status --self=false | sort -k 2)
|
done <<< $(tailscale status --self=false | sort -k 2)
|
||||||
|
|
||||||
_COLUMNS=$COLUMNS
|
_COLUMNS=$COLUMNS
|
||||||
# Force options to display in one column
|
# Force options to display in one column
|
||||||
COLUMNS=80
|
COLUMNS=80
|
||||||
select item in "${items[@]}" Cancel; do
|
while [ "${#items[@]}" -gt 1 ]; do
|
||||||
if [ $REPLY -eq ${#items[@]} ]; then
|
select item in "${items[@]}" Cancel; do
|
||||||
echo ""
|
if [[ "$REPLY" =~ ^[0-9]+$ ]]; then
|
||||||
fi
|
# Number selections -- break immediately
|
||||||
echo ${hostnames[$((REPLY - 1))]}
|
if [ $REPLY -eq $((1 + ${#items[@]})) ]; then
|
||||||
break;
|
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
|
done
|
||||||
COLUMNS=$_COLUMNS
|
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
|
# SSH shorthands, same as before but for tailscale nodes
|
||||||
|
@ -93,3 +106,6 @@ export PATH="$PATH:~/.local/bin"
|
||||||
|
|
||||||
# Password Store
|
# Password Store
|
||||||
export PASSWORD_STORE_ENABLE_EXTENSIONS=true
|
export PASSWORD_STORE_ENABLE_EXTENSIONS=true
|
||||||
|
|
||||||
|
# Use gpg-agent-ssh
|
||||||
|
export SSH_AUTH_SOCK=/run/user/1000/gnupg/S.gpg-agent.ssh
|
||||||
|
|
Loading…
Add table
Reference in a new issue