Krolyxon
Branch master

Branches

Refs →

aurora.localbintms

31 lines · 737 B · Bourne Again Shell (bash)

1#!/usr/bin/env bash
2
3if [[ $# -eq 1 ]]; then
4 selected=$(realpath -- "$1") || exit 1
5else
6 selected=$( {
7 tmux list-sessions -F '#S' 2>/dev/null
8 find ~/code/dev ~/code/repos ~/code/rust -mindepth 1 -maxdepth 1 -type d
9 } | fzf)
10fi
11
12if [[ -z $selected ]]; then
13 exit 0
14fi
15
16# an existing session picked from the list: just go there
17if [[ ! -d $selected ]]; then
18 selected_name=$selected
19else
20 selected_name=$(basename -- "$selected" | tr '.:' '__')
21fi
22
23if [[ -z $TMUX ]]; then
24 exec tmux new-session -A -s "$selected_name" -c "$selected"
25fi
26
27if ! tmux has-session -t="$selected_name" 2> /dev/null; then
28 tmux new-session -ds "$selected_name" -c "$selected"
29fi
30
31tmux switch-client -t="$selected_name"