AlanGreene / starter

Dotfiles starter project for new machines
1 stars 1 forks source link

Automatically join tmux session #38

Open AlanGreene opened 2 years ago

AlanGreene commented 2 years ago
#!/bin/sh
# https://github.com/tmshn/dotfiles/blob/master/bin/autotmux

if ! type tmux > /dev/null 2>&1; then
    echo 'tmux is not available.' >&2
    exit 1
fi

if [ -n "${TMUX}" ]; then
    echo 'already in tmux session.' >&2
    exit
fi

if tmux has-session 2> /dev/null; then
    tmux attach
    exit
fi

readonly config="${XDG_CONFIG_HOME}/tmux/tmux.conf"
if [ ! -e "${config}" ]; then
    echo 'config file not found!' >&2
    exit 1
fi

tmux -f "${config}" new

Test this out and modify as needed.

AlanGreene commented 2 years ago

validation / autocompletion of tmux config https://github.com/tmuxinator/tmuxinator/issues/811#issuecomment-1230967077

AlanGreene commented 2 years ago

useful commands:

AlanGreene commented 1 year ago

other ideas:

create debug session (from https://github.com/openshift-pipelines/toolbox/blob/main/scripts/debug-tmux.sh) question: is `C-m` equivalent to `Enter`? ``` #!/usr/bin/env bash # # This script start a TMUX session targeting a cluster to debug it KUBECONFIG_NAME=$1 set -eu -o pipefail #SESSION_NAME=${KUBECONFIG_NAME} SESSION_NAME=$(echo ${KUBECONFIG_NAME} | tr '.' '_' ) KUBECONFIG=${HOME}/.kube/${KUBECONFIG_NAME} # Guess Namespace # FIXME: this is ugly echo "Detecting…" TEKTON_NAMESPACE="" kubectl --kubeconfig="${KUBECONFIG}" get namespace | grep "tekton-pipelines" && { echo " Running in kubernetes, tekton-pipelines namespace" TEKTON_NAMESPACE="tekton-pipelines" } || { echo -n "" } kubectl --kubeconfig="${KUBECONFIG}" get namespace | grep "openshift-pipelines" && { echo " Running in kubernetes, tekton-pipelines namespace" TEKTON_NAMESPACE="openshift-pipelines" } || { echo -n "" } if [[ $TEKTON_NAMESPACE == "" ]]; then echo "Tekton is not present in the cluster, nothing to debug…" exit 1 fi # FIXME: add helpers like # - watch tekton resource in the namespace # - watch pods in this namespace, … echo "Creating a session ${SESSION_NAME}…" tmux new-session -d -s ${SESSION_NAME} -n main tmux setenv -t ${SESSION_NAME} KUBECONFIG ${KUBECONFIG} tmux send-keys -t ${SESSION_NAME}:main "export KUBECONFIG=${KUBECONFIG}" C-m tmux send-keys -t ${SESSION_NAME}:main "tmux new-window -n controllers-logs kail --since=1h --ns=${TEKTON_NAMESPACE}" C-m if [[ $TEKTON_NAMESPACE == "openshift-pipelines" ]]; then tmux send-keys -t ${SESSION_NAME}:main "tmux new-window -n operator-logs kail --since=1h --ns=openshift-operators --deploy=openshift-pipelines-operator" C-m elif [[ $TEKTON_NAMESPACE == "tekton-pipelines" ]]; then tmux send-keys -t ${SESSION_NAME}:main "tmux new-window -n operator-logs kail --since=1h --ns=tekton-operator" C-m fi tmux send-keys -t ${SESSION_NAME}:main "tmux select-window -t main" C-m tmux send-keys -t ${SESSION_NAME}:main C-l echo "Attaching the session…" tmux attach-session -t ${SESSION_NAME} ```
AlanGreene commented 1 year ago

https://github.com/tmux-plugins/tmux-sensible