diff --git a/config/tmux/tmux.conf b/config/tmux/tmux.conf index a22db3a4..2414ebf3 100644 --- a/config/tmux/tmux.conf +++ b/config/tmux/tmux.conf @@ -13,10 +13,8 @@ bind -T copy-mode-vi v send -X begin-selection bind -T copy-mode-vi y send -X copy-selection-and-cancel # Pane Controls -bind -n M-Enter run-shell \ - "[[ $(tmux list-panes | wc -l) -eq 1 ]] && \ - tmux splitw -h -c '#{pane_current_path}' || \ - tmux splitw -v -c '#{pane_current_path}'" +bind -n M-Enter split-window -v -c "#{pane_current_path}" +bind -n M-S-Enter split-window -h -c "#{pane_current_path}" bind h split-window -v -c "#{pane_current_path}" bind v split-window -h -c "#{pane_current_path}" bind x kill-pane diff --git a/migrations/1778752973.sh b/migrations/1778752973.sh index 7604b0e4..7a3079e5 100644 --- a/migrations/1778752973.sh +++ b/migrations/1778752973.sh @@ -1,28 +1,21 @@ -echo "Add Alt+Enter smart split keybinding to tmux" +echo "Add Alt+Enter and Alt+Shift+Enter split keybindings to tmux" tmux_config="$HOME/.config/tmux/tmux.conf" -if [[ -f $tmux_config ]] && ! grep -q "bind -n M-Enter run-shell" "$tmux_config"; then - if grep -q '^bind ? display-popup .*omarchy-menu-tmux-keybindings' "$tmux_config"; then - sed -i '/^bind ? display-popup .*omarchy-menu-tmux-keybindings/a bind -n M-Enter run-shell \\ -"[[ $(tmux list-panes | wc -l) -eq 1 ]] \&\& \\ -tmux splitw -h -c '\''#{pane_current_path}'\'' || \\ -tmux splitw -v -c '\''#{pane_current_path}'\''"' "$tmux_config" - elif grep -q '^bind q source-file .*Configuration reloaded' "$tmux_config"; then - sed -i '/^bind q source-file .*Configuration reloaded/a bind -n M-Enter run-shell \\ -"[[ $(tmux list-panes | wc -l) -eq 1 ]] \&\& \\ -tmux splitw -h -c '\''#{pane_current_path}'\'' || \\ -tmux splitw -v -c '\''#{pane_current_path}'\''"' "$tmux_config" - else - cat >>"$tmux_config" <<'EOF' +if [[ -f $tmux_config ]]; then + changed=0 -# Smart split: horizontal from one pane, vertical otherwise -bind -n M-Enter run-shell \ -"[[ $(tmux list-panes | wc -l) -eq 1 ]] && \ -tmux splitw -h -c '#{pane_current_path}' || \ -tmux splitw -v -c '#{pane_current_path}'" -EOF + if ! grep -qxF 'bind -n M-Enter split-window -v -c "#{pane_current_path}"' "$tmux_config"; then + printf '\nbind -n M-Enter split-window -v -c "#{pane_current_path}"\n' >>"$tmux_config" + changed=1 fi - omarchy-restart-tmux + if ! grep -qxF 'bind -n M-S-Enter split-window -h -c "#{pane_current_path}"' "$tmux_config"; then + printf 'bind -n M-S-Enter split-window -h -c "#{pane_current_path}"\n' >>"$tmux_config" + changed=1 + fi + + if (( changed )); then + omarchy-restart-tmux + fi fi