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.
- Bash
- Tilix (native package, not Flatpak)
- Tilix sessions launched via absolute path, e.g.
tilix --session ~/.config/tilix/sessions/main.json
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"
)
These are mandatory for session-based execution to work correctly.
- At the TOP of ~/.bashrc
[[ $- != *i* ]] && return
source "$HOME/tilix/index.sh"
Nothing above this except comments.
- 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
}
- .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.
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.
- Tilix cannot load multiple saved sessions into one window
- tilix -a session-add-* cannot load sessions
- Always launch sessions using absolute paths
execreplaces the shell by design