this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tmopen script

+77
+77
scripts/tmopen.sh
··· 1 + #!/usr/bin/env bash 2 + 3 + # tmopen - Open a tmux session for a given project 4 + # Usage: tmopen <path_or_url> [session_name] 5 + 6 + set -e 7 + 8 + # Function to get the session name from a path 9 + get_session_name() { 10 + local path=$1 11 + basename "$path" | tr '.' '-' 12 + } 13 + 14 + # Function to extract repo name from URL 15 + get_repo_name_from_url() { 16 + local url=$1 17 + # Extract the part after the last slash and before .git (if present) 18 + basename=$(basename "$url") 19 + echo "${basename%.git}" | tr '.' '-' 20 + } 21 + 22 + # Check if a parameter was provided 23 + if [ -z "$1" ]; then 24 + echo "Usage: tmopen <path_or_url> [session_name]" 25 + exit 1 26 + fi 27 + 28 + input=$1 29 + is_url=false 30 + 31 + # Check if the input is a URL 32 + if [[ $input == http* ]]; then 33 + is_url=true 34 + fi 35 + 36 + if [ "$is_url" = true ]; then 37 + # Handle URL (git repository) 38 + TEMP_DIR=$(mktemp -d) 39 + echo "Cloning repository to temporary directory: $TEMP_DIR" 40 + git clone "$input" "$TEMP_DIR" 41 + project_path=$TEMP_DIR 42 + # For URLs, get the session name from the repo name in the URL 43 + auto_session_name=$(get_repo_name_from_url "$input") 44 + else 45 + # Handle local path 46 + if [ ! -d "$input" ]; then 47 + echo "Error: Directory does not exist: $input" 48 + exit 1 49 + fi 50 + project_path=$(realpath "$input") 51 + # For local paths, get the session name from the directory name 52 + auto_session_name=$(get_session_name "$project_path") 53 + fi 54 + 55 + # Use the provided session name if available, otherwise use the auto-generated one 56 + if [ -n "$2" ]; then 57 + session_name="$2" 58 + echo "Using provided session name: $session_name" 59 + else 60 + session_name="$auto_session_name" 61 + echo "Using auto-generated session name: $session_name" 62 + fi 63 + 64 + # Check if the session already exists 65 + if tmux has-session -t "$session_name" 2>/dev/null; then 66 + echo "Session '$session_name' already exists..." 67 + else 68 + echo "Creating new session '$session_name' at $project_path" 69 + tmux new-session -d -s "$session_name" -c "$project_path" 70 + fi 71 + 72 + # Connect to the new session 73 + if [ -n "$TMUX" ]; then 74 + tmux switch-client -t "$session_name" 75 + else 76 + tmux attach-session -t "$session_name" 77 + fi