Skip to content

Commit

Permalink
Rename the dump helper and add functions to dump windows
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertAudi committed Mar 31, 2019
1 parent b4bc7a5 commit a4f046c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/commands/backup.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function __tsm::commands::backup::session() {

function __tsm::commands::backup() {
local session_dump
session_dump="$(__tsm::helpers::dump)" || return $status
session_dump="$(__tsm::helpers::dump_panes)" || return $status

local filename="$(__tsm::utils::filename).$(__tsm::utils::random).txt"
[[ -n "$1" ]] && filename="${1}.${filename}"
Expand Down
2 changes: 1 addition & 1 deletion src/commands/save.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# asked to confirm before override the existing one.
function __tsm::commands::save() {
local session_dump
session_dump="$(__tsm::helpers::dump)" || return $status
session_dump="$(__tsm::helpers::dump_panes)" || return $status

local filename="${1:-$(__tsm::utils::filename)}.txt"
local session_file="${TSM_SESSIONS_DIR}/$filename"
Expand Down
27 changes: 17 additions & 10 deletions src/helpers/dump.zsh
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# Dump the list of tmux windows using the following
# three components separated by a tab character `\t`:
# - Session name
# - Window name
# - Window working directory path
#
# Caveat: Window panes are ignored.
function __tsm::helpers::dump() {
# FIXME: Fail if tmux is not running
# TODO: Find a way to dump all panes including enough info to be able to restore them
# Dump the list of tmux panes
function __tsm::helpers::dump_panes() {
command tmux list-panes -a -F "${__tsm_tmux_formats[pane]}"
}

# Dump the list of tmux panes prefixed with the list type (pane)
function __tsm::helpers::dump_panes::annotated() {
command tmux list-panes -a -F "pane${__tsm_tmux_delimiter}${__tsm_tmux_formats[pane]}"
}

# Dump the list of tmux windows
function __tsm::helpers::dump_windows() {
command tmux list-windows -a -F "${__tsm_tmux_formats[window]}"
}

# Dump the list of tmux windows prefixed with the list type (window)
function __tsm::helpers::dump_windows::annotated() {
command tmux list-windows -a -F "window${__tsm_tmux_delimiter}${__tsm_tmux_formats[window]}"
}
9 changes: 9 additions & 0 deletions src/helpers/get_window_index.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function __tsm::helpers::get_active_window_index() {
command tmux list-windows -t "$1" -F "#{window_flags} #{window_index}" \
| command awk '$1 ~ /\*/ { print $2; }'
}

function __tsm::helpers::get_alternate_window_index() {
command tmux list-windows -t "$1" -F "#{window_flags} #{window_index}" \
| command awk '$1 ~ /-/ { print $2; }'
}

0 comments on commit a4f046c

Please sign in to comment.