Compare commits
4 Commits
5de5edca67
...
1507b0c3c4
Author | SHA1 | Date |
---|---|---|
Matej Janezic | 1507b0c3c4 | |
Matej Janezic | 9837828c72 | |
Matej Janezic | dbc860d89d | |
Matej Janezic | 5cc4dac594 |
|
@ -75,6 +75,7 @@ history = 10000
|
|||
|
||||
[window]
|
||||
dynamic_title = true
|
||||
option_as_alt = "Both"
|
||||
|
||||
[window.dimensions]
|
||||
columns = 150
|
||||
|
|
|
@ -14,3 +14,5 @@
|
|||
|
||||
[init]
|
||||
defaultBranch = main
|
||||
[alias]
|
||||
blame = "!f() { [ -f .git-blame-ignore-revs ] && git blame --ignore-revs-file .git-blame-ignore-revs \"$@\" || git blame \"$@\"; }; f"
|
||||
|
|
|
@ -3,18 +3,27 @@
|
|||
if [[ $# -eq 1 ]]; then
|
||||
selected=$1
|
||||
else
|
||||
if ! [[ -f "$GGROOT/compiled" ]]; then
|
||||
find -L $GGROOT -mindepth 1 -maxdepth 5 -type d -name .git -prune | xargs -n 1 dirname > "$GGROOT/compiled"
|
||||
fi
|
||||
selected=$(cat "$GGROOT/compiled" | fzf --cycle --bind 'tab:toggle-up,btab:toggle-down')
|
||||
selected=$(ggman exec pwd 2>&1 >/dev/null \
|
||||
| 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
|
||||
|
||||
if [[ -z $selected ]]; then
|
||||
exit 0
|
||||
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)
|
||||
|
||||
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
|
||||
|
|
|
@ -1,9 +1,58 @@
|
|||
#!/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
|
||||
selected=$1
|
||||
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
|
||||
|
||||
if [[ -z $selected ]]; then
|
||||
|
@ -23,3 +72,6 @@ if ! tmux has-session -t=$selected_name 2> /dev/null; then
|
|||
fi
|
||||
|
||||
tmux switch-client -t $selected_name
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
|
|
@ -4,6 +4,9 @@ export XDG_CACHE_HOME="$HOME/.cache"
|
|||
export XDG_DATA_HOME="$HOME/.local/share"
|
||||
export XDG_STATE_HOME="$HOME/.local/state"
|
||||
|
||||
# ~/.local/bin
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
|
||||
# brew sbin
|
||||
export PATH="/opt/homebrew/sbin:$PATH"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
alias z="exec zsh"
|
||||
alias t="tmux a || tmux new-session -s $(whoami) -c ~"
|
||||
alias t="tmux a || ~/.config/tmux/tmux-sessionizer ~"
|
||||
alias n=nvim_ve
|
||||
# alias vim=nvim_ve
|
||||
alias s="ssh-menu"
|
||||
|
@ -22,3 +22,9 @@ alias ci="glab ci list"
|
|||
alias bm=batman
|
||||
alias grow="~/.local/bin/cbonsai -liWC -M 15 -t 2 -w 60 -s $(date +%s)"
|
||||
alias clean_ds_store='find . -name ".DS_Store" -type f -delete -print'
|
||||
|
||||
# ruff
|
||||
alias ruffme="ruff format && ruff check --fix"
|
||||
|
||||
# clipboard
|
||||
alias xcp="xclip -selection c"
|
||||
|
|
|
@ -10,23 +10,6 @@ function nvim_ve {
|
|||
|
||||
alias nvim=nvim_ve
|
||||
|
||||
function ffb {
|
||||
if ! [[ -f package.json ]]; then
|
||||
echo "no package.json"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -f yarn.lock ]]; then
|
||||
PACKAGE_MANAGER=yarn
|
||||
else
|
||||
PACKAGE_MANAGER=npm
|
||||
fi
|
||||
|
||||
if [[ -n $(grep "react-scripts" package.json) ]]; then
|
||||
BROWSER=none FORCE_COLOR=true "$PACKAGE_MANAGER" start | cat
|
||||
fi
|
||||
}
|
||||
|
||||
function afm {
|
||||
RES=$(curl -s "https://$1/api/monitoring/requirements")
|
||||
COUNT=$(echo "$RES" | grep -c $2)
|
||||
|
@ -71,7 +54,7 @@ function pyinit {
|
|||
|
||||
function lh {
|
||||
if [[ -z $1 ]]; then
|
||||
PORT=8000
|
||||
PORT=7999
|
||||
else
|
||||
PORT=$1
|
||||
fi
|
||||
|
@ -87,32 +70,6 @@ function dps {
|
|||
fi
|
||||
}
|
||||
|
||||
function get_dump {
|
||||
if [[ -z $1 ]]; then
|
||||
echo "provide ssh host"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -z $2 ]]; then
|
||||
echo "provide dump destination"
|
||||
return
|
||||
fi
|
||||
|
||||
selected=$(ssh "$1" docker ps --format "{{.Names}}" | fzf)
|
||||
|
||||
if [[ -z $selected ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
ssh "$1" docker exec "$selected" pg_dump -U db --format=c db >"$2$(date +'%Y-%m-%dT%H.%M.%S%z')"
|
||||
|
||||
}
|
||||
|
||||
function ggcompile {
|
||||
find -L "$GGROOT" -mindepth 1 -maxdepth 5 -type d -name .git -prune \
|
||||
-exec dirname {} \; >"$GGROOT/compiled"
|
||||
}
|
||||
|
||||
function tssh {
|
||||
if [[ -z $1 ]]; then
|
||||
echo "provide ssh host"
|
||||
|
@ -122,17 +79,3 @@ function tssh {
|
|||
ssh -t "$@" "command -v tmux && (tmux a || tmux new-session -s gorazd -c ~) || bash"
|
||||
}
|
||||
|
||||
function ssh-menu {
|
||||
selected=$(
|
||||
grep 'Host .*' ~/.ssh/config \
|
||||
| grep -v '*' \
|
||||
| sed 's/Host \(.*\)/\1/' \
|
||||
| fzf --cycle --bind 'tab:toggle-up,btab:toggle-down'
|
||||
)
|
||||
|
||||
if [[ -z $selected ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
ssh "$selected"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue