summaryrefslogtreecommitdiff
path: root/plugins/tmux/tmux.plugin.zsh
diff options
context:
space:
mode:
authorPeat Bakke <peat@peat.org>2023-10-19 02:49:38 -0700
committerGitHub <noreply@github.com>2023-10-19 11:49:38 +0200
commit104041a018dc9a3eb74f93815192dba4c9386e1a (patch)
treedf31e5bea119ceac519e632c359fa9702c617ab0 /plugins/tmux/tmux.plugin.zsh
parent0da416986aadbaf89dc5596b01f9b42403f4d9fd (diff)
downloadzsh-104041a018dc9a3eb74f93815192dba4c9386e1a.tar.gz
zsh-104041a018dc9a3eb74f93815192dba4c9386e1a.tar.bz2
zsh-104041a018dc9a3eb74f93815192dba4c9386e1a.zip
feat(tmux): add `tds` alias for directory sessions (#11987)
Diffstat (limited to 'plugins/tmux/tmux.plugin.zsh')
-rw-r--r--plugins/tmux/tmux.plugin.zsh13
1 files changed, 13 insertions, 0 deletions
diff --git a/plugins/tmux/tmux.plugin.zsh b/plugins/tmux/tmux.plugin.zsh
index 6ed91c447..72cdd4818 100644
--- a/plugins/tmux/tmux.plugin.zsh
+++ b/plugins/tmux/tmux.plugin.zsh
@@ -108,6 +108,19 @@ compdef _tmux _zsh_tmux_plugin_run
# Alias tmux to our wrapper function.
alias tmux=_zsh_tmux_plugin_run
+function _tmux_directory_session() {
+ # current directory without leading path
+ local dir=${PWD##*/}
+ # md5 hash for the full working directory path
+ local md5=$(printf '%s' "$PWD" | md5sum | cut -d ' ' -f 1)
+ # human friendly unique session name for this directory
+ local session_name="${dir}-${md5:0:6}"
+ # create or attach to the session
+ tmux new -As "$session_name"
+}
+
+alias tds=_tmux_directory_session
+
# Autostart if not already in tmux and enabled.
if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" && -z "$INTELLIJ_ENVIRONMENT_READER" ]]; then
# Actually don't autostart if we already did and multiple autostarts are disabled.