diff --git a/README.md b/README.md index 7598004..2d1af41 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,14 @@ To load the session layout simply run: You'll now have a new Tmux session with your previously defined awesome window in it. +To customize the `sessions_root` simply append the path at creation + + tmuxifier new-session my-awesome-session . + +or + + tmuxifier new-session my-awesome-session ~/.tmuxifier + [examples]: https://github.com/jimeh/tmuxifier/tree/master/examples ## Configure & Customize @@ -177,6 +185,29 @@ reason you need to disable it, just set `$TMUXIFIER_NO_COMPLETE`. export TMUXIFIER_NO_COMPLETE=1 ``` +### Custom Session Base Path + +```bash +export TMUXIFIER_SESSION_BASE_PATH=~/code +``` + +### Custom Template Path + +You can customize the template directory used by Tmuxifier by setting + +```bash +export TMUXIFIER_TEMPLATE_PATH="$HOME/.tmuxinator-templates" +export TMUXIFIER_SESSION_TEMPLATE_NAME="awesome-session" +export TMUXIFIER_WINDOW_TEMPLATE_NAME="awesome-window" +``` + +or for special cases + +``` +TMUXIFIER_SESSION_TEMPLATE_NAME=awesome-session tmuxifier new-window wilder +TMUXIFIER_WINDOW_TEMPLATE_NAME=awesome-window tmuxifier new-window wilder +``` + ## Inspiration - Tmuxifier is largely inspired by [Tmuxinator][]. diff --git a/lib/env.sh b/lib/env.sh index 73d50e1..b69febf 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -4,3 +4,31 @@ if [ -z "${TMUXIFIER_LAYOUT_PATH}" ]; then else export TMUXIFIER_LAYOUT_PATH="${TMUXIFIER_LAYOUT_PATH%/}" fi + +# Setup session base path. +if [ -z "${TMUXIFIER_SESSION_BASE_PATH}" ]; then + export TMUXIFIER_SESSION_BASE_PATH="~/Projects" +else + export TMUXIFIER_SESSION_BASE_PATH="${TMUXIFIER_SESSION_BASE_PATH%/}" +fi + +# Setup template path. +if [ -z "${TMUXIFIER_TEMPLATE_PATH}" ]; then + export TMUXIFIER_TEMPLATE_PATH="${TMUXIFIER}/templates" +else + export TMUXIFIER_TEMPLATE_PATH="${TMUXIFIER_TEMPLATE_PATH%/}" +fi + +# Setup session template name. +if [ -z "${TMUXIFIER_SESSION_TEMPLATE_NAME}" ]; then + export TMUXIFIER_SESSION_TEMPLATE_NAME="session" +else + export TMUXIFIER_SESSION_TEMPLATE_NAME="${TMUXIFIER_SESSION_TEMPLATE_NAME%.sh}" +fi + +# Setup window template name. +if [ -z "${TMUXIFIER_WINDOW_TEMPLATE_NAME}" ]; then + export TMUXIFIER_WINDOW_TEMPLATE_NAME="window" +else + export TMUXIFIER_WINDOW_TEMPLATE_NAME="${TMUXIFIER_WINDOW_TEMPLATE_NAME%.sh}" +fi diff --git a/libexec/tmuxifier-new-session b/libexec/tmuxifier-new-session index 6787f2f..cc2f6ac 100755 --- a/libexec/tmuxifier-new-session +++ b/libexec/tmuxifier-new-session @@ -27,11 +27,23 @@ if [ -z "$1" ]; then fi layout_name="$1" +session_path="$TMUXIFIER_SESSION_BASE_PATH/${layout_name}" layout_file="$TMUXIFIER_LAYOUT_PATH/${layout_name}.session.sh" -template="$TMUXIFIER/templates/session.sh" +template="$TMUXIFIER_TEMPLATE_PATH/$TMUXIFIER_SESSION_TEMPLATE_NAME.sh" + +if [ $# -eq 2 ]; then + if [ "$2" == "." ]; then + session_path="$(pwd)" + else + session_path=$2 + fi +fi + +# Attempt to make session_path relative to users home directory +session_path=${session_path//$HOME/"~"} if [ ! -f "$template" ]; then - echo "tmuxifier: session layout template not found: $template" >&2 + echo "tmuxifier: session layout template not found \"$template\"" >&2 exit 1 fi @@ -44,6 +56,7 @@ if [ -f "$layout_file" ]; then fi content="$(cat "$template")" +content="${content//\{\{SESSION_PATH\}\}/$session_path}" echo "${content//\{\{SESSION_NAME\}\}/$layout_name}" > "$layout_file" if [ -n "$EDITOR" ]; then diff --git a/libexec/tmuxifier-new-window b/libexec/tmuxifier-new-window index 726cd16..ef8b8fd 100755 --- a/libexec/tmuxifier-new-window +++ b/libexec/tmuxifier-new-window @@ -28,7 +28,7 @@ fi layout_name="$1" layout_file="$TMUXIFIER_LAYOUT_PATH/${layout_name}.window.sh" -template="$TMUXIFIER/templates/window.sh" +template="$TMUXIFIER_TEMPLATE_PATH/$TMUXIFIER_WINDOW_TEMPLATE_NAME.sh" if [ ! -f "$template" ]; then echo "tmuxifier: window layout template not found: $template" >&2 diff --git a/templates/session.sh b/templates/session.sh index e8b3975..ef20da8 100644 --- a/templates/session.sh +++ b/templates/session.sh @@ -1,6 +1,6 @@ # Set a custom session root path. Default is `$HOME`. # Must be called before `initialize_session`. -#session_root "~/Projects/{{SESSION_NAME}}" +#session_root "{{SESSION_PATH}}" # Create session with specified name if it does not already exist. If no # argument is given, session name will be based on layout file name.