From 078cea40e9133c660f6f1baee249b923a3c6a6e5 Mon Sep 17 00:00:00 2001 From: Darren Pearce Date: Wed, 5 Feb 2014 14:22:55 -0700 Subject: [PATCH 1/3] customizable session_root --- README.md | 14 ++++++++++++++ lib/env.sh | 7 +++++++ libexec/tmuxifier-new-session | 13 +++++++++++++ templates/session.sh | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7598004..9834530 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,12 @@ 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 +``` + ## Inspiration - Tmuxifier is largely inspired by [Tmuxinator][]. diff --git a/lib/env.sh b/lib/env.sh index 73d50e1..3dc6224 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -4,3 +4,10 @@ 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 diff --git a/libexec/tmuxifier-new-session b/libexec/tmuxifier-new-session index 6787f2f..3fc671e 100755 --- a/libexec/tmuxifier-new-session +++ b/libexec/tmuxifier-new-session @@ -27,9 +27,21 @@ 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" +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 exit 1 @@ -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/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. From 2aecafe242b9c0256e6d191ddb0867b7522ad84c Mon Sep 17 00:00:00 2001 From: Darren Pearce Date: Wed, 5 Feb 2014 23:04:41 -0700 Subject: [PATCH 2/3] added customizable template directory --- README.md | 8 ++++++++ lib/env.sh | 7 +++++++ libexec/tmuxifier-new-session | 4 ++-- libexec/tmuxifier-new-window | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9834530..e5faddc 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,14 @@ export TMUXIFIER_NO_COMPLETE=1 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" +``` + ## Inspiration - Tmuxifier is largely inspired by [Tmuxinator][]. diff --git a/lib/env.sh b/lib/env.sh index 3dc6224..9e99ee4 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -11,3 +11,10 @@ if [ -z "${TMUXIFIER_SESSION_BASE_PATH}" ]; then 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 diff --git a/libexec/tmuxifier-new-session b/libexec/tmuxifier-new-session index 3fc671e..04d3c4e 100755 --- a/libexec/tmuxifier-new-session +++ b/libexec/tmuxifier-new-session @@ -29,7 +29,7 @@ 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/session.sh" if [ $# -eq 2 ]; then if [ "$2" == "." ]; then @@ -43,7 +43,7 @@ fi 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 diff --git a/libexec/tmuxifier-new-window b/libexec/tmuxifier-new-window index 726cd16..05b6705 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/window.sh" if [ ! -f "$template" ]; then echo "tmuxifier: window layout template not found: $template" >&2 From 9025bea623d3b714d0e42b73e587f756b89a33d3 Mon Sep 17 00:00:00 2001 From: Darren Pearce Date: Wed, 5 Feb 2014 23:21:18 -0700 Subject: [PATCH 3/3] added customizable template names --- README.md | 9 +++++++++ lib/env.sh | 14 ++++++++++++++ libexec/tmuxifier-new-session | 2 +- libexec/tmuxifier-new-window | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e5faddc..2d1af41 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,15 @@ 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 diff --git a/lib/env.sh b/lib/env.sh index 9e99ee4..b69febf 100644 --- a/lib/env.sh +++ b/lib/env.sh @@ -18,3 +18,17 @@ if [ -z "${TMUXIFIER_TEMPLATE_PATH}" ]; then 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 04d3c4e..cc2f6ac 100755 --- a/libexec/tmuxifier-new-session +++ b/libexec/tmuxifier-new-session @@ -29,7 +29,7 @@ fi layout_name="$1" session_path="$TMUXIFIER_SESSION_BASE_PATH/${layout_name}" layout_file="$TMUXIFIER_LAYOUT_PATH/${layout_name}.session.sh" -template="$TMUXIFIER_TEMPLATE_PATH/session.sh" +template="$TMUXIFIER_TEMPLATE_PATH/$TMUXIFIER_SESSION_TEMPLATE_NAME.sh" if [ $# -eq 2 ]; then if [ "$2" == "." ]; then diff --git a/libexec/tmuxifier-new-window b/libexec/tmuxifier-new-window index 05b6705..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_TEMPLATE_PATH/window.sh" +template="$TMUXIFIER_TEMPLATE_PATH/$TMUXIFIER_WINDOW_TEMPLATE_NAME.sh" if [ ! -f "$template" ]; then echo "tmuxifier: window layout template not found: $template" >&2