.bashrc: Add shorthands for ssh-ing into tailscale nodes
This commit is contained in:
parent
190c3559e4
commit
25182187ae
45
bash/.bashrc
45
bash/.bashrc
|
@ -20,10 +20,12 @@ alias moshtmp="mosh --ssh=\"ssh -o 'UserKnownHostsFile /dev/null' -o 'StrictHost
|
||||||
|
|
||||||
# SSH with automatic "screen"
|
# SSH with automatic "screen"
|
||||||
function sshscr() {
|
function sshscr() {
|
||||||
|
[ -z "$1" ] && return
|
||||||
ssh -t $@ screen -RR -d
|
ssh -t $@ screen -RR -d
|
||||||
}
|
}
|
||||||
|
|
||||||
function moshscr() {
|
function moshscr() {
|
||||||
|
[ -z "$1" ] && return
|
||||||
mosh $@ -- screen -RR -d
|
mosh $@ -- screen -RR -d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,5 +43,48 @@ function sshunlock() {
|
||||||
set +o pipefail
|
set +o pipefail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 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
|
||||||
|
local name=$(echo "$line" | awk '{ print $2 }')
|
||||||
|
local ip=$(echo "$line" | awk '{ print $1 }')
|
||||||
|
items+=("$name ($ip)")
|
||||||
|
hostnames+=("$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;
|
||||||
|
done
|
||||||
|
COLUMNS=$_COLUMNS
|
||||||
|
}
|
||||||
|
|
||||||
|
# SSH shorthands, same as before but for tailscale nodes
|
||||||
|
function moshscrts() {
|
||||||
|
moshscr $(tsselect)
|
||||||
|
}
|
||||||
|
|
||||||
|
function sshscrts() {
|
||||||
|
sshscr $(tsselect)
|
||||||
|
}
|
||||||
|
|
||||||
|
function _ssh() {
|
||||||
|
[ -z "$1" ] && return
|
||||||
|
ssh $@
|
||||||
|
}
|
||||||
|
|
||||||
|
function sshts() {
|
||||||
|
_ssh $(tsselect)
|
||||||
|
}
|
||||||
|
|
||||||
# Add local to path
|
# Add local to path
|
||||||
export PATH="$PATH:~/.local/bin"
|
export PATH="$PATH:~/.local/bin"
|
||||||
|
|
Loading…
Reference in a new issue