Skip to content

m-ox/tilix-session-workflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tilix Directory-Driven Sessions & Auto-Exec

This repo implements a directory-based intent system for Tilix sessions.

When a shell enters specific directories, it automatically executes commands (e.g. SSH into hosts, attach to containers).
This works for:

  • normal terminal opens
  • splits / tabs
  • Tilix sessions loaded from JSON

The implementation is intentionally minimal and timing-correct.


Requirements

  • Bash
  • Tilix (native package, not Flatpak)
  • Tilix sessions launched via absolute path, e.g.
    tilix --session ~/.config/tilix/sessions/main.json
    

Files in this repo

tilix/index.sh Defines the dispatcher function. No side effects at load time.

tilix/targets.conf Maps directory names → commands.

Example:

declare -A TILIX_DIR_MAP=(
  ["sshToBunnyheim"]="ssh bunnyheim"
  ["sshToHocus"]="ssh hocus"
  ["daas-db-management"]="docker exec -it postgres-v18-0-bookworm psql -U app_user -d postgres"
)

Required .bashrc changes

These are mandatory for session-based execution to work correctly.

  1. At the TOP of ~/.bashrc

Only run for interactive shells

[[ $- != *i* ]] && return

Load Tilix directory dispatcher (definitions only)

source "$HOME/tilix/index.sh"

Nothing above this except comments.

  1. At the VERY BOTTOM of ~/.bashrc
execute directory intent after Tilix finalizes CWD
PROMPT_COMMAND="tilix_dir_dispatch${PROMPT_COMMAND:+;$PROMPT_COMMAND}"

This is non-optional.

Tilix sessions set the working directory after the shell starts. PROMPT_COMMAND is the only reliable hook that sees the final $PWD.

index.sh contract (important)

index.sh must not:

  • exec at load time
  • inspect $PWD and act immediately
  • return early based on directory
  • assume the directory is final

It must only:

  • define tilix_dir_dispatch
  • source targets.conf

Minimal correct example:

[[ $- != *i* ]] && return

source "$HOME/tilix/targets.conf"

tilix_dir_dispatch() {
  [[ -n "$TILIX_DIR_EXECED" ]] && return

  base="$(basename "$PWD")"
  cmd="${TILIX_DIR_MAP[$base]}"

  if [[ -n "$cmd" ]]; then
    export TILIX_DIR_EXECED=1
    exec $cmd
  fi
}

Why this is structured this way

  • .bashrc runs before Tilix applies session directories
  • Session JSON directory values are applied after shell startup
  • Any exec logic in .bashrc will run too early and fail silently
  • PROMPT_COMMAND runs after directory stabilization
  • This design avoids race conditions and works across all Tilix entry paths.

Usage pattern

Directory names are the API.

Example layout:

~/tilix/dir/
├── sshToBunnyheim/
├── sshToHocus/
├── sshToPi/
└── daas-db-management/

Entering any of those directories triggers the mapped command exactly once.

Known constraints

  • Tilix cannot load multiple saved sessions into one window
  • tilix -a session-add-* cannot load sessions
  • Always launch sessions using absolute paths
  • exec replaces the shell by design

About

Tilix hasn't had major updates in years to fix alleged "issues". It just needed some... help.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages