edit-weechat
edit-weechat copied to clipboard
Terminal command is a little too strict
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
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.
@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.
@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
Actually I am interested in seeing your fork and implementing any general-enough stuff.
Can you send me a link to your fork?
On 22/05/17 01:24am, Immae wrote:
@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-- Reply to this email directly or view it on GitHub: https://github.com/keith/edit-weechat/issues/9#issuecomment-1128569672 You are receiving this because you were mentioned.
Message ID: @.***>
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)
Ok, I successfully implemented this in my fork. Thanks