Skip to content

Commit

Permalink
Join and Stop accept session number from List.
Browse files Browse the repository at this point in the history
`wemux list` outputs a list of all running sessions prefixed with a number.
`wemux join` and `wemux stop` can now be invoked with this number.
`wemux join 3` or `wemux j 3` would join the third server on the list.
`wemux stop` can now be passed either the number, or the session name.
If no argument is passed it will default to stopping the current session.
  • Loading branch information
zolrath committed Mar 29, 2012
1 parent 372fba0 commit dfd9647
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
9 changes: 8 additions & 1 deletion README.md
Expand Up @@ -144,13 +144,17 @@ tmux session.


$ wemux join Project X $ wemux join Project X
Changed wemux session from 'host' to 'project-x' Changed wemux session from 'host' to 'project-x'
$ wemux start
$ wemux $ wemux
$ wemux stop $ wemux stop
$ wemux reset $ wemux reset
Changed wemux session from 'project-x' to 'host' Changed wemux session from 'project-x' to 'host'
#### wemux join *sessionname* #### wemux join *sessionname*
Join wemux session with specified name. Join wemux session with specified name.
#### wemux join *sessionnumber*
Alternatively, enter the session number displayed next to the session name
in `wemux list`.

$ wemux j 3


### Resetting the Session Name ### Resetting the Session Name
In order to easily return to the default session you can run `wemux reset` In order to easily return to the default session you can run `wemux reset`
Expand All @@ -168,6 +172,9 @@ tmux session.
2. host <- current session 2. host <- current session
3. dont-get-lost 3. dont-get-lost


`wemux join` and `wemux stop` both accept either the name of a session, or
the number indicated next to the session name in `wemux list`.

Listing sessions can be disabled by setting `allow_session_list="false"` in Listing sessions can be disabled by setting `allow_session_list="false"` in
`/etc/wemux.conf` `/etc/wemux.conf`


Expand Down
40 changes: 27 additions & 13 deletions wemux
@@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# wemux by Matt Furden @zolrath # wemux by Matt Furden @zolrath
# version 2.1.1 # version 2.2.0
# #
# wemux allows you to start a shared tmux session using the command 'wemux'. # wemux allows you to start a shared tmux session using the command 'wemux'.
# Clients have the option of mirroring, which will give them read-only access, # Clients have the option of mirroring, which will give them read-only access,
Expand Down Expand Up @@ -39,7 +39,7 @@
############################################################################### ###############################################################################


# Current wemux version. # Current wemux version.
version="2.1.1" version="2.2.0"


# Setup and Configuration Files. # Setup and Configuration Files.
# Default settings, modify them in the /etc/wemux.conf file: # Default settings, modify them in the /etc/wemux.conf file:
Expand Down Expand Up @@ -250,6 +250,11 @@ change_session() {
new_session=`sanitize_session_name $@` new_session=`sanitize_session_name $@`
old_session=$session old_session=$session


# Get list of currently running sessions
session_names=(`echo $socket_prefix* | sed -e "s,$socket_prefix-,,g"`)
# If user joins a number, go to the session with that number in `wemux list`
[[ "$new_session" =~ ^[0-9]+$ ]] && new_session=${session_names[$new_session-1]}

if [ -z "$new_session" ]; then if [ -z "$new_session" ]; then
echo "Current wemux session: $session" echo "Current wemux session: $session"
elif [ "$new_session" == "$old_session" ]; then elif [ "$new_session" == "$old_session" ]; then
Expand All @@ -259,8 +264,7 @@ change_session() {
[ "$announce_session_change" == "true" ] && redirect=`$wemux display-message \ [ "$announce_session_change" == "true" ] && redirect=`$wemux display-message \
"$username has switched to session: $new_session" 2>&1` "$username has switched to session: $new_session" 2>&1`
echo "Changed wemux session from '$old_session' to '$new_session'" echo "Changed wemux session from '$old_session' to '$new_session'"
session=$new_session echo $new_session > ~/.wemux_last_session
echo $session > ~/.wemux_last_session
# Rebuild wemux prefix for new session name. # Rebuild wemux prefix for new session name.
build_wemux_prefix build_wemux_prefix
# Announce that the user has joined to new session. # Announce that the user has joined to new session.
Expand Down Expand Up @@ -325,20 +329,30 @@ host_mode() {


# Stop the wemux session and remove the socket file. # Stop the wemux session and remove the socket file.
stop_session() { stop_session() {
session_sockets=(`echo $socket_prefix*`)
# If a specific session is supplied:
if [ $1 ]; then
# If user enters a number, stop the session with that number in `wemux list`
if [[ $@ =~ ^[0-9]+$ ]]; then
socket=${session_sockets[$1-1]}
session=`echo $socket | sed -e "s,$socket_prefix-,,g"`
# Otherwise, stop the session with the supplied name.
else
session=`sanitize_session_name $@`
socket="$socket_prefix-$session"
fi
fi
# If the user doesn't pass an argument, stop current session.
if kill_session_successful; then if kill_session_successful; then
echo "wemux session on '$session' stopped." echo "wemux session on '$session' stopped."
else else
echo "No wemux session running on '$session'." echo "No wemux session running on '$session'"
fi fi
# If the socket file exists: # If the socket file exists:
if [ -e "$socket" ]; then if [ -e "$socket" ]; then
if rm $socket; then if ! rm $socket; then
echo "Removed '$socket'."
else
echo "Could not remove '$socket'. Please check file ownership." echo "Could not remove '$socket'. Please check file ownership."
fi fi
else
echo "The wemux socket '$socket' does not exist."
fi fi
} }


Expand All @@ -364,7 +378,7 @@ host_mode() {
fi fi
fi fi
if [ "$allow_user_list" == "true" ]; then if [ "$allow_user_list" == "true" ]; then
echo " [u] users: List all users currently connected to '$session'." echo " [u] users: List all users currently connected to '$session'"
fi fi
if [ "$allow_kick_user" == "true" ]; then if [ "$allow_kick_user" == "true" ]; then
echo " kick: Disconnect an SSH user, remove their wemux session." echo " kick: Disconnect an SSH user, remove their wemux session."
Expand All @@ -383,8 +397,8 @@ host_mode() {
case "$1" in case "$1" in
start|s) announce_connection "host" start_session;; start|s) announce_connection "host" start_session;;
attach|a) announce_connection "host" reattach;; attach|a) announce_connection "host" reattach;;
stop|st) stop_session;; stop|st) shift; stop_session $@;;
kill|k) stop_session;; kill|k) shift; stop_session $@;;
help|h) display_host_commands;; help|h) display_host_commands;;
join|j) shift; change_session $@;; join|j) shift; change_session $@;;
name|n) shift; change_session $@;; name|n) shift; change_session $@;;
Expand Down

0 comments on commit dfd9647

Please sign in to comment.