chore(tmux): cleanup tmux scripts

This commit is contained in:
2026-03-10 00:55:03 +01:00
parent 42a1672fb0
commit a47d944286
4 changed files with 23 additions and 32 deletions

View File

@@ -1,7 +1,5 @@
#!/usr/bin/env bash
source "$XDG_CONFIG_HOME/zsh/scripts.zsh"
if [[ $# -eq 1 ]]; then
selected=$1
else
@@ -12,7 +10,7 @@ if [[ -z $selected ]]; then
exit 0
fi
ggman clone $selected
ggman clone "$selected"
echo ""
read -p "press enter to continue..."

View File

@@ -6,8 +6,6 @@ if [[ -z ${NAME:+x} ]]; then
exit 1
fi
source "$XDG_CONFIG_HOME/zsh/scripts.zsh"
read -p "name: " project_name
if [[ -z $project_name ]]; then
@@ -19,7 +17,7 @@ if [[ -d "$GGROOT/no-remote/$project_name" ]]; then
fi
project="$GGROOT/no-remote/$project_name"
git init $project
git init "$project"
echo "# $project_name" >>"$project/README.md"
gitignore_template=$(
@@ -28,7 +26,7 @@ gitignore_template=$(
| fzf --cycle --bind 'tab:toggle-up,btab:toggle-down'
)
if ! [[ -z $gitignore_template ]]; then
if [[ -n $gitignore_template ]]; then
gitignore="$GGROOT/github.com/github/gitignore/$gitignore_template.gitignore"
echo "$gitignore"
echo "$project/.gitignore"
@@ -41,10 +39,8 @@ license_template=$(
| fzf --cycle --bind 'tab:toggle-up,btab:toggle-down'
)
if ! [[ -z $license_template ]]; then
if [[ -n $license_template ]]; then
license="$GGROOT/git.janezic.dev/janezicmatej/license/$license_template.license"
export YEAR="$(date '+%Y')"
envsubst <"$license" >"$project/LICENSE"
fi
ggcompile

View File

@@ -18,17 +18,15 @@ if [[ -z $selected ]]; then
exit 0
fi
selected_name="$(echo $selected | shasum -a 256 | head -c 4)_$(basename $selected | tr . _ | head -c 10)"
selected_name="$(echo "$selected" | shasum -a 256 | head -c 4)_$(basename "$selected" | tr . _ | head -c 10)"
tmux_running=$(pgrep tmux)
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s $selected_name -c $selected
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
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
tmux switch-client -t "$selected_name"

View File

@@ -4,22 +4,22 @@ function _preview {
file=$1; shift
host=$1; shift
j=$(cat $file \
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)
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\
HostName $hostname\
$([[ $port != "null" ]] && echo -e "\nPort $port")\
$([[ $jumps != "null" ]] && echo -e "\nProxyJump $jumps")
@@ -29,11 +29,11 @@ EOF)"
echo ""
host $hostname
host "$hostname"
echo ""
ping -c 1 -W 1 $hostname &>/dev/null \
ping -c 1 -W 1 "$hostname" &>/dev/null \
&& echo "Host is reachable!" \
|| echo "Host is not reachable!"
}
@@ -60,18 +60,17 @@ function main() {
fi
selected_name="ssh_$selected"
tmux_running=$(pgrep tmux)
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s $selected_name -c $selected 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 -c $selected ssh "$selected"
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
tmux switch-client -t "$selected_name"
}
main "$@"