gpakosz / .tmux

🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️
MIT License
21.8k stars 3.36k forks source link

Edit configuration keybinding not working with emacs for me #591

Closed tabuchid closed 2 years ago

tabuchid commented 2 years ago

When run C-a e I'm seeing the screen flash and thats it. Expecting ~/.tmux.conf.local to open in whats set as $EDITOR. I can confirm this works when I unset $EDITOR but with the following config I see a flash and then nothing.

# In my .zshrc
export ALTERNATE_EDITOR=""
export EDITOR="emacsclient -t"        
export VISUAL="emacsclient -c -a emacs"

I assume emacs is either crashing or hanging up? Having a bit of trouble figuring out where to start debugging. Any suggestions?

gpakosz commented 2 years ago

Hello @tabuchid 👋

Outside of tmux, what happens when you launch

$ $EDITOR ~/.tmux.conf.local

?

gpakosz commented 2 years ago

My expectation is that you're going to get

$ zsh: command not found: emacsclient -t

Because by default Zsh doesn't do word splitting on variable expansion

gpakosz commented 2 years ago

Can you also please do

$ ls -l /bin/sh

?

tabuchid commented 2 years ago

Hello @gpakosz 👋🏼 Thanks for the response and thank you for this excellent project.

My expectation is that you're going to get

$ zsh: command not found: emacsclient -t

Because by default Zsh doesn't do word splitting on variable expansion

Ah hah, That is indeed what I'm seeing

Can you also please do $ ls -l /bin/sh

❯ ls -l /bin/sh
-rwxr-xr-x  1 root  wheel  150384 Jul 14 10:48 /bin/sh
gpakosz commented 2 years ago

What I don't understand so far is that new-window is supposed to execute commands with /bin/sh and I'm wondering if /bin/sh on your system is also Zsh?

gpakosz commented 2 years ago

Does the following open Emacs?

$ sh -c "$EDITOR"
tabuchid commented 2 years ago

Does the following open Emacs?

$ sh -c "$EDITOR"

It does. After some googling about word splitting I've also confirmed that ${=EDITOR} ~/.tmux.conf.local opens emacs.

tabuchid commented 2 years ago

What I don't understand so far is that new-window is supposed to execute commands with /bin/sh and I'm wondering if /bin/sh on your system is also Zsh?

It doesn't appear so.

❯ /bin/sh --help
GNU bash, version 3.2.57(1)-release-(x86_64-apple-darwin21)
Usage:  /bin/sh [GNU long option] [option] ...
    /bin/sh [GNU long option] [option] script-file ...
GNU long options:
    --debug
    --debugger
    --dump-po-strings
    --dump-strings
    --help
    --init-file
    --login
    --noediting
    --noprofile
    --norc
    --posix
    --protected
    --rcfile
    --restricted
    --verbose
    --version
    --wordexp
Shell options:
    -irsD or -c command or -O shopt_option      (invocation only)
    -abefhkmnptuvxBCHP or -o option
Type `/bin/sh -c "help set"' for more information about shell options.
Type `/bin/sh -c help' for more information about shell builtin commands.
Use the `bashbug' command to report bugs.
tabuchid commented 2 years ago

I'm not sure if its portable or not, assuming not, but this works locally for me.

diff --git a/.tmux.conf b/.tmux.conf
index a23bdad..feb8d04 100644
--- a/.tmux.conf
+++ b/.tmux.conf
@@ -26,7 +26,7 @@ setw -q -g utf8 on
 set -g history-limit 5000                 # boost history

 # edit configuration
-bind e new-window -n "~/.tmux.conf.local" "EDITOR=\${EDITOR//mvim/vim} && EDITOR=\${EDITOR//gvim/vim} && \${EDITOR:-vim} ~/.tmux.conf.local && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\""
+bind e new-window -n "~/.tmux.conf.local" "EDITOR=\${=EDITOR//mvim/vim} && EDITOR=\${=EDITOR//gvim/vim} && \${=EDITOR:-vim} ~/.tmux.conf.local && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\""

 # reload configuration
 bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
gpakosz commented 2 years ago

${=EDITOR} is not portable.

Can you try

bind e new-window -n "~/.tmux.conf.local" "EDITOR=\${EDITOR//mvim/vim} && EDITOR=\${EDITOR//gvim/vim} && sh -c \"\${EDITOR:-vim} ~/.tmux.conf.local\" && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\""

please?

gpakosz commented 2 years ago

I pushed the gh-591 branch that should work for you

tabuchid commented 2 years ago

Branch gh-591 works!

tabuchid commented 2 years ago

Thank you @gpakosz! This has been a pleasure and I really appreciate the project.