Skip to content

customizable session_root when creating new sessions #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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][].
Expand Down
28 changes: 28 additions & 0 deletions lib/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 15 additions & 2 deletions libexec/tmuxifier-new-session
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libexec/tmuxifier-new-window
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion templates/session.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down