aboutsummaryrefslogtreecommitdiff
path: root/scripts/tmux_session_fzf
blob: c0934683f154c06b050a599687bea5f2fd883fa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
# vim: set filetype=sh
#
# Author: Cody Hiar
# Date: 2020-03-17
#
# Description: Select a tmux session with FZF
#
# Set options:
#   e: Stop script if command fails
#   u: Stop script if unset variable is referenced
#   x: Debug, print commands as they are executed
#   o pipefail:  If any command in a pipeline fails it all fails
#
# IFS: Internal Field Separator
set -euo pipefail
IFS=$'\n\t'

get_active_pane(){
    local SESSION="${1}"
    tmux list-windows -t "${SESSION}" | grep '(active)' | cut -c 1
}

TARGET=$(tmux ls | awk -F':' '{print $1}' | fzf-tmux -h)
if [[ -n "${TARGET}" ]]; then
    WINDOW=$(get_active_pane "${TARGET}")
    echo "${TARGET}:${WINDOW}" >> ~/tmux.log
    tmux switch-client -t "${TARGET}:${WINDOW}" 
fi