Skip to content

Instantly share code, notes, and snippets.

@mikiyaf
Created November 13, 2017 01:17
Show Gist options
  • Save mikiyaf/4244a7d038a8db4a8118515e9c508ad0 to your computer and use it in GitHub Desktop.
Save mikiyaf/4244a7d038a8db4a8118515e9c508ad0 to your computer and use it in GitHub Desktop.
tm - create new tmux session, or switch to existing one
tm() {
[[ -n "$TMUX" ]] && change="switch-client" || change="attach-session"
if [ $1 ]; then
tmux $change -t "$1" 2>/dev/null || (tmux new-session -d -s $1 && tmux $change -t "$1"); return
fi
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --exit-0) && tmux $change -t "$session" || echo "No sessions found."
}
# fs [FUZZY PATTERN] - Select selected tmux session
# - Bypass fuzzy finder if there's only one match (--select-1)
# - Exit if there's no match (--exit-0)
fs() {
local session
session=$(tmux list-sessions -F "#{session_name}" | \
fzf --query="$1" --select-1 --exit-0) &&
tmux switch-client -t "$session"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment