Skip to content

Instantly share code, notes, and snippets.

@dlains
Created January 15, 2019 06:06
Show Gist options
  • Save dlains/b28690d9975bec72c811b1824bfe3ee3 to your computer and use it in GitHub Desktop.
Save dlains/b28690d9975bec72c811b1824bfe3ee3 to your computer and use it in GitHub Desktop.
Quick tmux session script
#!/usr/bin/env bash
# Create a quick tmux session with an editor window and
# a console window. The session will be named after the
# directory supplied as an argument.
#
# Usage:
# qs path
#
# Check the arguments. There should be one argument only.
if [[ $# < 1 ]]; then
printf "%b" "Error, not enough arguments.\n" >&2
printf "%b" "Usage: qs path\n" >&2
exit 1
elif [[ $# > 1 ]]; then
printf "%b" "Error, too many arguments.\n" >&2
printf "%b" "Usage: qs path\n" >&2
exit 2
fi
# Verify that the argument is a directory.
if [[ ! -d $1 ]]; then
printf "%b" "Error, the given argument is not a directory.\n" >&2
printf "%b" "Usage: qs path\n" >&2
exit 3
fi
NAME=`basename $1`
cd $1
tmux new -s $NAME -n editor -d
tmux send-keys -t $NAME $EDITOR C-m
tmux new-window -n console -t $NAME
tmux select-window -t $NAME:1
tmux attach -t $NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment