Skip to content

Instantly share code, notes, and snippets.

@akirill0v
Created January 15, 2015 10:47
Show Gist options
  • Save akirill0v/8b924bddb3506da65f40 to your computer and use it in GitHub Desktop.
Save akirill0v/8b924bddb3506da65f40 to your computer and use it in GitHub Desktop.
Позволяет автоподключаться к терминалу при входе в папку
#!/bin/sh
#
# Attach or create tmux session named the same as current directory.
session_name="$(basename "$PWD" | tr . -)"
not_in_tmux() {
[ -z "$TMUX" ]
}
session_exists() {
tmux list-sessions | sed -E 's/:.*$//' | grep -q "^$session_name$"
}
create_detached_session() {
(TMUX='' tmux new-session -Ad -s "$session_name")
}
create_if_needed_and_attach() {
if not_in_tmux; then
tmux new-session -As "$session_name"
else
if ! session_exists; then
create_detached_session
fi
tmux switch-client -t "$session_name"
fi
}
create_if_needed_and_attach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment