Skip to content

Instantly share code, notes, and snippets.

@thefotios
Created May 12, 2012 07:15
Show Gist options
  • Select an option

  • Save thefotios/2664890 to your computer and use it in GitHub Desktop.

Select an option

Save thefotios/2664890 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# GistID: 2664890
# This wrapper for wemux allows for more intelligent server selection
# Pretty much, it lists if you have servers running and allows you to select one
# It also allows you to just hit enter to pick the default
# Or type a name to create a new one
function full_path(){
readlink -f $1
}
function log(){
logger -t wemux -s $@
}
function real_bin(){
path=$1
# Get the base name of my function to override
name=$(basename "$path")
# Call with echo to get full path according to man page
paths=$(which -a $name)
# Remove this script from the paths list
paths=${paths//$path}
# This is the real bin if it's the only one
if [[ $paths ]]; then
# Print the first remaining path
path=`echo $paths | awk '{print $1}'`
fi
echo $path
}
# Get the real binary if we named ours wemux
# Wouldn't it be nice if bash had some sort of 'super' function?!
wemux=$(real_bin $0)
echo $wemux
# If args are passed, just pass them along and exit
if [[ $@ ]]; then
$wemux $@
exit
fi
# Get a list of servers
list=$($wemux list)
if [[ ! $list =~ 'No wemux servers' ]]; then
echo "${list}"
echo ""
echo "* Select a server by number/name"
fi
# Regex if a current server is marked
regex=" <- current server$"
if [[ $list =~ $regex ]]; then
echo "* Hit Enter for current server";
fi
echo "* Type a name for a new server"
printf "Server: "
read choice
if [ -n "${choice}" ]; then
echo "Joining $choice"
$wemux join $choice && $wemux
else
echo "Joining current server"
$wemux
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment