Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal command is a little too strict #9

Open
immae opened this issue Jan 1, 2020 · 6 comments
Open

Terminal command is a little too strict #9

immae opened this issue Jan 1, 2020 · 6 comments

Comments

@immae
Copy link

immae commented Jan 1, 2020

tmux users would probably like to be able to set their terminal command to something like:

tmux split-window "_the_command_; tmux wait-for -S weechat_editor" \; resize-pane -Z \; wait-for weechat_editor

Which is currently impossible in the current state, since an "-e" is added to the terminal, and the command is necessarily added at the end.

I can make the implementation if necessary, but would a change like this be accepted:

  • If the terminal command contains a {}, then use python format on it
  • otherwise, use the current state (terminal -e editor), for backward compatibility
@graywolf
Copy link

graywolf commented Apr 22, 2020

While I agree that current way is bit too strict (I've personally hit a wall with urxvt's -e behaving differently than xterm's), there are workarounds. I'm using the following:

+   $ cat bin/tmux-weechat-edit
#!/bin/sh
set -eu
set -x

# Drop leading -e
shift

pane=$(tmux split-window -P "$@; tmux wait-for -S weechat_editor")
tmux resize-pane -Z
tmux wait-for weechat_editor

And I just set my terminal to this script.

@Farzat07
Copy link
Contributor

@immae can you please elaborate on the {} part? I am writing a fork of this project, and this is indeed an issue I want to fix. I am interested in your approach as it seems more flexible.

@immae
Copy link
Author

immae commented May 17, 2022

@Farzat07 this is a bit old and I forked the script for other additional reasons, but here is my implementation of what I meant above:

def hook_editor_process(terminal, editor, path, buf):                                                                   
    if "{}" in editor:                                                                                                  
        editor_cmd = editor.format(path)                                                                                
    else:                                                                                                               
        editor_cmd = "{} {}".format(editor, path)                                                                       
    if "{}" in terminal:                                                                                                
        command = terminal.format(editor_cmd)                                                                           
    else:                                                                                                               
        command = "{} -e \"{}\"".format(terminal, editor_cmd)                                                           
    weechat.hook_process(command, 0, "editor_process_cb", buf)                                                          

The goal is to not break existing situations, except when the editor or terminal setting contains a {} (which should be rare enough), in which case we replace it like above

@Farzat07
Copy link
Contributor

Farzat07 commented May 17, 2022 via email

@immae
Copy link
Author

immae commented May 17, 2022

I don’t have a fork, I just keep the file in my local directory:
edit.txt (github doesn’t let me send a .py file, just rename it)

Notable changes:

  • The change given above
  • Moving the default file to ~/.cache/message.txt (XDG_CACHE_HOME) rather than the weechat config dir
  • A way to specify an existing file rather than starting with a blank one (not well implemented, I’m trying to keep the diff as small as possible so I had to use global variables)
  • A new command edit_send that reads a file and writes is immediately in the buffer (without going through an editor)

@Farzat07
Copy link
Contributor

Ok, I successfully implemented this in my fork.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants