Skip to content

Instantly share code, notes, and snippets.

@joshkunz
Created June 16, 2021 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshkunz/bcd1630555498a95c384701f52213dfa to your computer and use it in GitHub Desktop.
Save joshkunz/bcd1630555498a95c384701f52213dfa to your computer and use it in GitHub Desktop.
A Fish shortcut + autocomplete for tmux sessions.
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
# Connect to or create the given tmux session.
function tmuxs --argument session
tmux attach -t $session; or tmux new-session -s $session
end
# List the active tmux sessions in a format that is usable by autocomplete.
function _tmux_active_sessions
set -l fmt '#{session_last_attached} #{session_name} #{session_windows}'
for session_line in (tmux list-sessions -F $fmt 2>/dev/null | sort -rn)
echo $session_line | read -l session_last_attached session_name session_windows
set -l attached_str (date -d @$session_last_attached +"%m/%d %H:%M")
set -l desc "$session_windows windows, last $attached_str"
printf "%s\t%s\n" $session_name $desc
end
end
complete --command tmuxs --no-files --keep-order -a "(_tmux_active_sessions)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment