feat(tmux): sessionizer and ssher fzf preview and hashed names
This commit is contained in:
parent
dbc860d89d
commit
9837828c72
|
@ -3,18 +3,27 @@
|
||||||
if [[ $# -eq 1 ]]; then
|
if [[ $# -eq 1 ]]; then
|
||||||
selected=$1
|
selected=$1
|
||||||
else
|
else
|
||||||
if ! [[ -f "$GGROOT/compiled" ]]; then
|
selected=$(ggman exec pwd 2>&1 >/dev/null \
|
||||||
find -L $GGROOT -mindepth 1 -maxdepth 5 -type d -name .git -prune | xargs -n 1 dirname > "$GGROOT/compiled"
|
| fzf --cycle \
|
||||||
fi
|
--bind 'tab:toggle-up,btab:toggle-down' \
|
||||||
selected=$(cat "$GGROOT/compiled" | fzf --cycle --bind 'tab:toggle-up,btab:toggle-down')
|
--header "Navigate with ARROW KEYS or TAB/S-TAB. Select with ENTER." \
|
||||||
|
--border "double" \
|
||||||
|
--border-label "tmux-sessionizer" \
|
||||||
|
--ansi \
|
||||||
|
--highlight-line \
|
||||||
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $selected ]]; then
|
if [[ -z $selected ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
path=$selected
|
||||||
|
while [[ "$path" != "" && ! -e "$path/.sessionizer" ]]; do
|
||||||
|
path=${path%/*}
|
||||||
|
done
|
||||||
|
|
||||||
selected_name=$(basename "$selected" | tr . _)
|
selected_name="$(cat $path/.sessionizer)_$(basename $selected | tr . _ | head -c 10)_$(echo $selected | shasum -a 256 | head -c 4)"
|
||||||
tmux_running=$(pgrep tmux)
|
tmux_running=$(pgrep tmux)
|
||||||
|
|
||||||
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
|
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
|
||||||
|
|
|
@ -1,9 +1,58 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
function _preview {
|
||||||
|
file=$1; shift
|
||||||
|
host=$1; shift
|
||||||
|
|
||||||
|
j=$(cat $file \
|
||||||
|
| jc --ssh-conf \
|
||||||
|
| jq -r ".[] \
|
||||||
|
| select(.host == \"$host\") \
|
||||||
|
| .jumps = (if (.proxyjump | type == \"array\" and length > 0) then (.proxyjump | join(\",\")) else \"null\" end)" \
|
||||||
|
)
|
||||||
|
|
||||||
|
user=$(jq -r '.user' <<<$j)
|
||||||
|
port=$(jq -r '.port' <<<$j)
|
||||||
|
hostname=$(jq -r '.hostname' <<<$j)
|
||||||
|
jumps=$(jq -r '.jumps' <<<$j)
|
||||||
|
|
||||||
|
|
||||||
|
echo "$(cat <<EOF
|
||||||
|
User $user
|
||||||
|
HostName $hostname\
|
||||||
|
$([[ $port != "null" ]] && echo -e "\nPort $port")\
|
||||||
|
$([[ $jumps != "null" ]] && echo -e "\nProxyJump $jumps")
|
||||||
|
|
||||||
|
command:
|
||||||
|
ssh $user@$hostname$([[ $port != "null" ]] && echo -n " -p $port")$([[ $jumps != "null" ]] && echo -n " -J $jumps")
|
||||||
|
EOF)"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
host $hostname
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
ping -c 1 -W 1 $hostname &>/dev/null \
|
||||||
|
&& echo "Host is reachable!" \
|
||||||
|
|| echo "Host is not reachable!"
|
||||||
|
}
|
||||||
|
|
||||||
|
export -f _preview
|
||||||
|
|
||||||
|
function main() {
|
||||||
if [[ $# -eq 1 ]]; then
|
if [[ $# -eq 1 ]]; then
|
||||||
selected=$1
|
selected=$1
|
||||||
else
|
else
|
||||||
selected="$(grep 'Host .*' ~/.ssh/config | grep -v '*' | sed 's/Host \(.*\)/\1/' | fzf --cycle --bind 'tab:toggle-up,btab:toggle-down')"
|
selected="$(rg -N --no-heading 'Host .*' ~/.ssh \
|
||||||
|
| sed 's/Host \(.*\)/\1/' \
|
||||||
|
| SHELL=$(which bash) fzf --cycle \
|
||||||
|
--bind 'tab:toggle-up,btab:toggle-down' \
|
||||||
|
--delimiter ':' \
|
||||||
|
--with-nth 2 \
|
||||||
|
--preview "_preview {1} {2}" \
|
||||||
|
| cut -d ":" -f2
|
||||||
|
)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z $selected ]]; then
|
if [[ -z $selected ]]; then
|
||||||
|
@ -23,3 +72,6 @@ if ! tmux has-session -t=$selected_name 2> /dev/null; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tmux switch-client -t $selected_name
|
tmux switch-client -t $selected_name
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
|
|
Loading…
Reference in New Issue