Skip to content

Commit 7896d1b

Browse files
committed
bin/dotfiles: Edit config/tmux.init
1 parent 6f869e0 commit 7896d1b

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

bin/dotfiles

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dotfiles_config() {
3434
'config/dotfiles/shellrc/hooks/post-shellrc.sh'
3535
'config/shellrc'
3636
'config/vim/vimrc'
37+
'config/tmux.init'
3738
'config/tmux.conf'
3839
'config/ranger/rc.conf'
3940
'config/ranger/rifle.conf'

config/shellrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,8 @@ alias shellrc='"$EDITOR" "$DOTFILES_HOME/config/shellrc"'
681681
alias sync='sudo "$(which syncf)"'
682682
alias t-display-restore='tmux setenv -g DISPLAY :0'
683683
alias t='tmux'
684-
alias ta='tmux-attach'
684+
alias ta='tmux-init || tmux-attach'
685+
alias tmux-init='bash "$(custom-env-resolve "config/tmux.init")"'
685686
alias tf='tail -F'
686687
alias tmain='tmux-attach main'
687688
alias tp='tp_get'

config/tmux.init

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
set -xv
5+
6+
session_name='ssh'
7+
8+
main() {
9+
if [[ "${1:-}" == 'setup_session' ]]; then
10+
set_env
11+
setup_session "$@"
12+
else
13+
create_session "$@"
14+
fi
15+
}
16+
17+
set_env() {
18+
export DISPLAY=:0
19+
tmux setenv DISPLAY "$DISPLAY"
20+
}
21+
22+
create_session() {
23+
if tmux has-session -t "$session_name"; then
24+
if [[ "$session_name" == 'ssh' ]]; then
25+
echo "Session has already started." >&2
26+
exit 1
27+
else
28+
tmux kill-session -t "$session_name"
29+
fi
30+
fi
31+
32+
tmux new-session -d -s "$session_name" "exec bash $(realpath "$0") setup_session"
33+
34+
if [[ -z "${TMUX:-}" ]]; then
35+
tmux attach -t "$session_name"
36+
else
37+
tmux switch-client -t "$session_name"
38+
fi
39+
}
40+
41+
new_window() {
42+
local dir="$1"
43+
local name="${2:-}"
44+
45+
if [[ -z "$name" ]]; then
46+
name="$(basename "$dir")"
47+
fi
48+
49+
tmux new-window -c "$dir" -n "$name"
50+
}
51+
52+
send() {
53+
tmux send-keys "$@"
54+
}
55+
56+
setup_session() {
57+
new_window ~ scratch
58+
send 'vim' Enter
59+
60+
new_window ~/.dotfiles dotfiles
61+
send 'gst' Enter
62+
tmux split-window -c "#{pane_current_path}"
63+
send 'cd custom' Enter
64+
send 'gst' Enter
65+
tmux select-pane -t 1
66+
67+
tmux select-window -t scratch
68+
}
69+
70+
main "$@"

0 commit comments

Comments
 (0)