Compare commits

...

2 Commits

7 changed files with 51 additions and 212 deletions

3
.gitignore vendored
View File

@@ -7,9 +7,6 @@
!.git-blame-ignore-revs !.git-blame-ignore-revs
!README.md !README.md
# allow some stuff to be pushed
!alacritty
# zsh # zsh
!zsh !zsh
zsh/* zsh/*

View File

@@ -1,82 +0,0 @@
[colors]
draw_bold_text_with_bright_colors = true
[colors.bright]
black = "0x45403d"
blue = "0x7daea3"
cyan = "0x89b482"
green = "0xa9b665"
magenta = "0xd3869b"
red = "0xea6962"
white = "0xd4be98"
yellow = "0xd8a657"
[colors.normal]
black = "0x45403d"
blue = "0x7daea3"
cyan = "0x89b482"
green = "0xa9b665"
magenta = "0xd3869b"
red = "0xea6962"
white = "0xd4be98"
yellow = "0xd8a657"
[colors.primary]
background = "0x32302f"
foreground = "0xd4be98"
[cursor]
unfocused_hollow = true
[cursor.style]
blinking = "On"
shape = "Block"
[env]
TERM = "xterm-256color"
[font]
size = 15
[font.bold]
family = "JetBrainsMono Nerd Font"
style = "Bold"
[font.bold_italic]
family = "JetBrainsMono Nerd Font"
style = "Bold Italic"
[font.italic]
family = "JetBrainsMono Nerd Font"
style = "Italic"
[font.normal]
family = "JetBrainsMono Nerd Font"
style = "Regular"
[[keyboard.bindings]]
chars = "\f"
key = "R"
mode = "~Vi|~Search"
mods = "Command"
[[keyboard.bindings]]
action = "ScrollPageUp"
key = "PageUp"
mode = "~Alt"
[[keyboard.bindings]]
action = "ScrollPageDown"
key = "PageDown"
mode = "~Alt"
[scrolling]
history = 10000
[window]
dynamic_title = true
option_as_alt = "Both"
[window.dimensions]
columns = 150
lines = 36

View File

@@ -4,72 +4,50 @@ function _ssh_menu_preview {
file=$1; shift file=$1; shift
host=$1; shift host=$1; shift
j=$(cat $file \ # show host block from ssh config
| jc --ssh-conf \ awk -v h="$host" '
| jq -r ".[] \ $0 == "Host " h { found=1 }
| select(.host == \"$host\") \ found && /^[^ \t]/ && $0 != "Host " h { exit }
| .jumps = (\ found
if (.proxyjump | type == \"array\" and length > 0) then \ ' "$file"
(.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 "" echo ""
if command -v host 2>&1 >/dev/null; then # resolve hostname for reachability check
host $hostname hostname=$(awk -v h="$host" '
$0 == "Host " h { found=1; next }
found && /^[^ \t]/ { exit }
found && /HostName/ { print $2 }
' "$file")
if command -v host &>/dev/null; then
host "${hostname:-$host}"
echo "" echo ""
fi fi
ping -c 1 -W 1 $hostname &>/dev/null \ ping -c 1 -W 1 "${hostname:-$host}" &>/dev/null \
&& echo "Host is reachable!" \ && echo "reachable" \
|| echo "Host is not reachable!" || echo "not reachable"
} }
export -f _ssh_menu_preview export -f _ssh_menu_preview
function ssh-menu { function _ssh_menu_select {
selected="$(rg -N --no-heading '^Host .*' ~/.ssh \ rg -N --no-heading '^Host .*' ~/.ssh \
| sed 's/Host \(.*\)/\1/' | sort \ | sed 's/Host \(.*\)/\1/' | sort \
| SHELL=$(which bash) fzf --cycle \ | SHELL=$(which bash) fzf \
--bind 'tab:toggle-up,btab:toggle-down' \
--delimiter ':' \ --delimiter ':' \
--with-nth 2 \ --with-nth 2 \
--preview "_ssh_menu_preview {1} {2}" \ --preview "_ssh_menu_preview {1} {2}" \
--preview-label "ssh config info" \ --preview-label "ssh config info" \
--header "Navigate with ARROW KEYS or TAB/S-TAB. Select with ENTER." \
--border "double" \
--border-label "ssh-menu" \ --border-label "ssh-menu" \
--ansi \
--highlight-line \
| cut -d ":" -f2 | cut -d ":" -f2
)"
if [[ -z $selected ]]; then
return
fi
ssh "$selected"
} }
ssh-menu case "${1:-}" in
-s) _ssh_menu_select ;;
*)
selected="$(_ssh_menu_select)"
[[ -n $selected ]] && ssh "$selected"
;;
esac

View File

@@ -23,7 +23,7 @@ echo "# $project_name" >>"$project/README.md"
gitignore_template=$( gitignore_template=$(
find "$GGROOT"/github.com/github/gitignore/*.gitignore -exec basename {} \; \ find "$GGROOT"/github.com/github/gitignore/*.gitignore -exec basename {} \; \
| sed 's/\(.*\)\.gitignore/\1/' \ | sed 's/\(.*\)\.gitignore/\1/' \
| fzf --cycle --bind 'tab:toggle-up,btab:toggle-down' | fzf
) )
if [[ -n $gitignore_template ]]; then if [[ -n $gitignore_template ]]; then
@@ -36,7 +36,7 @@ fi
license_template=$( license_template=$(
find "$GGROOT"/git.janezic.dev/janezicmatej/license/*.license -exec basename {} \; \ find "$GGROOT"/git.janezic.dev/janezicmatej/license/*.license -exec basename {} \; \
| sed 's/\(.*\)\.license/\1/' \ | sed 's/\(.*\)\.license/\1/' \
| fzf --cycle --bind 'tab:toggle-up,btab:toggle-down' | fzf
) )
if [[ -n $license_template ]]; then if [[ -n $license_template ]]; then

View File

@@ -4,13 +4,8 @@ if [[ $# -eq 1 ]]; then
selected=$1 selected=$1
else else
selected=$(ggman ls \ selected=$(ggman ls \
| fzf --cycle \ | fzf \
--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" \ --border-label "tmux-sessionizer" \
--ansi \
--highlight-line \
) )
fi fi

View File

@@ -1,76 +1,24 @@
#!/usr/bin/env bash #!/usr/bin/env bash
function _preview { if [[ $# -eq 1 ]]; then
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
selected=$1 selected=$1
else else
selected="$(rg -N --no-heading '^Host .*' ~/.ssh \ selected="$(~/.config/bin/ssh-menu -s)"
| sed 's/Host \(.*\)/\1/' \ fi
| SHELL=$(which bash) fzf --cycle \
--bind 'tab:toggle-up,btab:toggle-down' \
--delimiter ':' \
--with-nth 2 \
--preview "_preview {1} {2}" \
| cut -d ":" -f2
)"
fi
if [[ -z $selected ]]; then if [[ -z $selected ]]; then
exit 0 exit 0
fi fi
selected_name="ssh_$selected" selected_name="ssh_$selected"
if [[ -z $TMUX ]] && ! tmux list-sessions 2>/dev/null; then if [[ -z $TMUX ]] && ! tmux list-sessions 2>/dev/null; then
tmux new-session -s "$selected_name" ssh "$selected" tmux new-session -s "$selected_name" ssh "$selected"
exit 0 exit 0
fi fi
if ! tmux has-session -t="$selected_name" 2>/dev/null; then if ! tmux has-session -t="$selected_name" 2>/dev/null; then
tmux new-session -ds "$selected_name" ssh "$selected" tmux new-session -ds "$selected_name" ssh "$selected"
fi fi
tmux switch-client -t "$selected_name" tmux switch-client -t "$selected_name"
}
main "$@"

View File

@@ -22,3 +22,6 @@ export NAME="Matej Janežič"
# starship nest config into a folder, default is ~/.config/starship.toml # starship nest config into a folder, default is ~/.config/starship.toml
export STARSHIP_CONFIG="$XDG_CONFIG_HOME/starship/config.toml" export STARSHIP_CONFIG="$XDG_CONFIG_HOME/starship/config.toml"
# fzf
export FZF_DEFAULT_OPTS="--cycle --bind 'tab:toggle-up,btab:toggle-down' --pointer '>' --color '16' --border 'double' --ansi --highlight-line --header 'Navigate with ARROW KEYS or TAB/S-TAB. Select with ENTER.'"