forked from strom/dotfiles
41 lines
1 KiB
Bash
Executable file
41 lines
1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# shellcheck shell=bash
|
|
|
|
# Presents the caller a list of git projects and creates/attaches a tmux session with identical name
|
|
# Usage example: alias tms='command tms ~/dev/projects'
|
|
|
|
# shellcheck source=../../lib/common.sh
|
|
source "${0%/*}/../share/dotfiles/lib/common.sh" || exit 1
|
|
|
|
if [[ ! -d $1 ]]; then
|
|
_die "Need projects path as argument"
|
|
fi
|
|
|
|
if ! _has_all fd fzf tmux; then
|
|
_die "Need fd, fzf and tmux"
|
|
fi
|
|
|
|
path=$(fd --hidden --exact-depth=2 --type d --glob '.git' --print0 "$1" \
|
|
| sed -z 's,/.git/$,,g' \
|
|
| fzf --read0 --scheme=path --bind=ctrl-r:toggle-sort)
|
|
|
|
if [[ -z $path ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
path=${path%%/}
|
|
project=${path##*/}
|
|
session=${project/./_}
|
|
|
|
if ! _is_tmux; then
|
|
# attach or create new session if not inside tmux
|
|
tmux new-session -ADs "$session" -c "$path"
|
|
else
|
|
# inside tmux, same as above but create detached
|
|
if ! tmux has-session -t="$session" 2>/dev/null; then
|
|
tmux new-session -ds "$session" -c "$path"
|
|
fi
|
|
tmux switch-client -t "$project"
|
|
fi
|
|
|
|
# vi: set ft=sh ts=4 sw=0 sts=-1 sr noet nosi tw=80 fdm=manual:
|