refactor: reorganize scripts to idiomatic locations

This commit is contained in:
2026-03-11 14:14:24 +01:00
parent 68302ad3d6
commit 80444180d2
9 changed files with 15 additions and 14 deletions

16
tmux/scripts/tmux-ggclone Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
if [[ $# -eq 1 ]]; then
selected=$1
else
read -p "url: " selected
fi
if [[ -z $selected ]]; then
exit 0
fi
ggman clone "$selected"
echo ""
read -p "press enter to continue..."

46
tmux/scripts/tmux-new-project Executable file
View File

@@ -0,0 +1,46 @@
#!/usr/bin/env bash
if [[ -z ${NAME:+x} ]]; then
echo "missing name"
sleep 2
exit 1
fi
read -p "name: " project_name
if [[ -z $project_name ]]; then
exit 0
fi
if [[ -d "$GGROOT/no-remote/$project_name" ]]; then
exit 0
fi
project="$GGROOT/no-remote/$project_name"
git init "$project"
echo "# $project_name" >>"$project/README.md"
gitignore_template=$(
find "$GGROOT"/github.com/github/gitignore/*.gitignore -exec basename {} \; \
| sed 's/\(.*\)\.gitignore/\1/' \
| fzf --cycle --bind 'tab:toggle-up,btab:toggle-down'
)
if [[ -n $gitignore_template ]]; then
gitignore="$GGROOT/github.com/github/gitignore/$gitignore_template.gitignore"
echo "$gitignore"
echo "$project/.gitignore"
cat "$gitignore" >>"$project/.gitignore"
fi
license_template=$(
find "$GGROOT"/git.janezic.dev/janezicmatej/license/*.license -exec basename {} \; \
| sed 's/\(.*\)\.license/\1/' \
| fzf --cycle --bind 'tab:toggle-up,btab:toggle-down'
)
if [[ -n $license_template ]]; then
license="$GGROOT/git.janezic.dev/janezicmatej/license/$license_template.license"
export YEAR="$(date '+%Y')"
envsubst <"$license" >"$project/LICENSE"
fi

32
tmux/scripts/tmux-sessionizer Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(ggman ls \
| 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
selected_name="$(echo "$selected" | shasum -a 256 | head -c 4)_$(basename "$selected" | tr . _ | head -c 10)"
if [[ -z $TMUX ]] && ! tmux list-sessions 2>/dev/null; then
tmux new-session -s "$selected_name" -c "$selected"
exit 0
fi
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
tmux new-session -ds "$selected_name" -c "$selected"
fi
tmux switch-client -t "$selected_name"

76
tmux/scripts/tmux-ssher Executable file
View File

@@ -0,0 +1,76 @@
#!/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="$(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
exit 0
fi
selected_name="ssh_$selected"
if [[ -z $TMUX ]] && ! tmux list-sessions 2>/dev/null; then
tmux new-session -s "$selected_name" ssh "$selected"
exit 0
fi
if ! tmux has-session -t="$selected_name" 2>/dev/null; then
tmux new-session -ds "$selected_name" ssh "$selected"
fi
tmux switch-client -t "$selected_name"
}
main "$@"