Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ list of functionality provided.*
own custom aliases, but `screenopen` gives lay-users easy access to
`screen`'s key functionality - detachable shell sessions.

* `tmuxls`, `tmuxopen`, and `tmuxcmd` provide parallel functionality to the
`screen` utilities for users of `tmux`.

* `gitsyncfork` syncs a Git repository with its upstream master. Useful for
pulling in updates to a forked GitHub repo.

Expand All @@ -85,8 +88,8 @@ list of functionality provided.*

### Behavior

* Displays the names of any open `screen` sessions when a new shell is
launched.
* Displays the names of any open `screen` or `tmux` sessions when a new shell
is launched.

## Copyright and License

Expand Down
11 changes: 11 additions & 0 deletions commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ if command -v screens > /dev/null; then
fi
)
fi

if command -v tmuxls > /dev/null; then
(
tmuxls=$(tmuxls 2>/dev/null)
if [[ -n "$tmuxls" ]]; then
echo "Open tmux sessions: $(wc -w <<<"$tmuxls")"
echo " $(tr '\n' ' ' <<<"$tmuxls")"
fi
)
fi

30 changes: 30 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,36 @@ screencmd() {
}
fi # if screen is installed

if command -v tmux > /dev/null; then
# Prints the currently open tmux sessions.
tmuxls() {
tmux list-sessions -F '#S'
}

# Opens a tmux session with a given name, either creating a new session or
# attaching to one that already exists.
tmuxopen() {
local session="${1:?Must specify a tmux session name.}"
tmux new-session -d -s "$session" 2>/dev/null || true
tmux attach-session -t "$session"
}

# Creates a tmux session (if it doesn't already exist), and then sends
# the given commands to it.
tmuxcmd() {
local session="${1:?Must specify a tmux session name.}"
shift
if (( $# == 0 )); then
pg::err "Must provide a command to run"
return 1
fi
tmux new-session -d -s "$session" 2>/dev/null || true
tmux send-keys -t "$session" "$*" C-m
printf "Wrote '%s' to '%s'\nTo open run:\n tmuxopen '%s'\nthen <Ctrl>+b d to detach.\n" \
"$*" "$session" "$session"
}
fi # if tmux is installed

# Grep ps command
# Inspiration: http://www.commandlinefu.com/commands/view/977/
# Alternately: http://code.google.com/p/psgrep/
Expand Down
1 change: 1 addition & 0 deletions info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ open common alias for different systems' open-with-default-app
command; e.g. `open foo.png`.
screenopen NAME opens a screen session with useful defaults; detaches any
existing connection and logs the session to /tmp.
tmuxopen NAME opens a tmux session, creating or attaching as needed.
wait_ext blocks until the PIDs passed as arguments are finished.
wait_port blocks until the ports passed as arguments are listening for
requests.
Expand Down