summaryrefslogtreecommitdiff
path: root/.local/bin/fzy-tmux-project
blob: b4cd23e1c001e3305446e1389935122631c2c0d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh

set -eu

CONFIG_PATH="$XDG_CONFIG_HOME/fzy-tmux-project"

search_dirs=$(cat "$CONFIG_PATH" | sed "s|~|$HOME|g")
dir=$(find "$search_dirs" -mindepth 1 -maxdepth 1 -type d | fzy) || exit 0
[ ! -d "$dir" ] && exit 1
name=$(basename "$dir" | tr . _)

[ -z "$TMUX" ] && ! pgrep tmux >/dev/null && exec tmux new -s "$name" -c "$dir"

! tmux has -t "$name" 2>/dev/null && tmux new -ds "$name" -c "$dir"
tmux switchc -t "$name"