tmux start session from dir

This commit is contained in:
thek4n 2025-01-25 01:50:37 +03:00
parent 667badeb9c
commit 9d2915895b
3 changed files with 37 additions and 1 deletions

View File

@ -1,7 +1,7 @@
readonly TARGETS="\ readonly TARGETS="\
colors:.config/terminal-colors.d colors:.config/terminal-colors.d
less:.lesskey .infokey less:.lesskey .infokey
tmux:.config/tmux .tmux .config/systemd/user/tmux.service .local/bin/tmux_start_session.sh .local/bin/tmux_list_sessions.sh .local/bin/tmux_attach_session.sh .local/bin/tmux_kill_sessions.sh tmux:.config/tmux .tmux .config/systemd/user/tmux.service .local/bin/tmux_start_session.sh .local/bin/tmux_list_sessions.sh .local/bin/tmux_attach_session.sh .local/bin/tmux_kill_sessions.sh .local/bin/tmux_start_projects.sh
t: t:
note: note:
zsh:.config/zsh .zshenv .inputrc %colors zsh:.config/zsh .zshenv .inputrc %colors

View File

@ -207,4 +207,5 @@ bind -T copy-mode-vi WheelDownPane select-pane \; send-keys -X -N 2 scroll-down
# Session managment # Session managment
bind a display-popup -EE -w 80% -h 80% -B '~/.local/bin/tmux_attach_session.sh' bind a display-popup -EE -w 80% -h 80% -B '~/.local/bin/tmux_attach_session.sh'
bind s display-popup -EE -w 80% -h 80% -B '~/.local/bin/tmux_start_session.sh' bind s display-popup -EE -w 80% -h 80% -B '~/.local/bin/tmux_start_session.sh'
bind S display-popup -EE -w 40% -h 80% -B '~/.local/bin/tmux_start_projects.sh'
bind k display-popup -EE -w 80% -h 80% -B '~/.local/bin/tmux_kill_sessions.sh' bind k display-popup -EE -w 80% -h 80% -B '~/.local/bin/tmux_kill_sessions.sh'

View File

@ -0,0 +1,35 @@
#!/bin/sh
export FZF_DEFAULT_OPTS="\
${FZF_DEFAULT_OPTS}
--no-multi
--marker=''
--border=rounded
--border-label-pos=bottom
--border-label=' Start session '
--color='border:grey,label:grey'
"
project_dir="$(find "${HOME}" -maxdepth 3 -type d -not -path '*/.*' | sed "s%^${HOME}%~%" | fzf | sed "s%^~%${HOME}%")"
readonly project_dir
if [ -z "${project_dir}" ]; then
exit 0
fi
if [ ! -d "${project_dir}" ]; then
printf 'Directory "%s" not found' "${project_dir}" >&2
exit 1
fi
session="$(basename "${project_dir}")"
if ! tmux has-session -t "${session}" 2>/dev/null; then
tmux new-session -d -n 1 -c "${project_dir}" -s "$(basename "${project_dir}")"
fi
tmux switch-client -t "${session}"