Running tig?


#1

I am trying to puzzle out the best way to use tig with kakoune, currently I tend to drop out of kakoune and run tig. Better ways?


#2

I usually pop a new terminal with i3 and just run tig. This way, I have kakoune along side tig.

What kind of integration between the two tools do you have in mind? Something like magit?


#3

I’m also thinking that it will be great if Kakoune could use line-flags to display added lines (via using dff on file constantly)


#4

What I use for running external terminal programs is the repl command (repl tig for example).
How it works is that it spawns a new terminal window with the command running on top and as I use I3 as my window manager, I can control the way I want to see it.

Regarding the integration, I really fail to see a good way of integrating tig (or any other external git program) onto kakoune. Magit is an awesome piece of software but I find it using emacs only as an application platform and not integrating it really (didn’t use emacs much so I might be wrong on that.). I think that having an external program managing stuff is better for the kakoune philosophy than creating an interface on top of it.

I do miss a program like magit though.


#5

Actually, :repl tig is a solid solution, oddly enough I didn’t go to that by default.


#6

I use the same pattern recommended for ranger integration, and it works great for tig:

This way I don’t really care what terminal I’m in, I can just flip over to tig in any of them. And it gets even smoother when I can implement some user-mode commands for quick access to certain parts of tig:

def tig-blame -override -docstring 'Open blame in tig for current file and line' %{ 
    suspend "tig blame +%val{cursor_line} %val{buffile} &&fg" 
}

map global user t ':suspend "tig &&fg"<ret>' -docstring 'launch tig'
map global user b ':tig-blame<ret>' -docstring 'show blame (with tig)'

It should be noted that the above code sample uses “suspend” which is covered on the Ranger wiki page I linked to above.

If all you’re doing is wanting to flip from kakoune to “some cli thing” and back to kakoune, suspend is a great tool.


#7

Thanks for this! went to try it out, but some of the syntax changed (even after updating to define-command I can’t launch it). Would you mind updating the snippet to the current kak release?


#8

I realized that I tweaked this script a little bit to fit my use-case of

  • Suspend my kak client
  • Run a given cli command
  • When command exits successfully, bring kak client back to the foreground.

Below is my modified version:

def suspend-and-resume \
    -override \
    -params 1..2 \
    -docstring 'suspend-and-resume <cli command> [<kak command after resume>]' \
    %{ evaluate-commands %sh{

    nohup sh -c "sleep 0.01; osascript -e 'tell application \"System Events\" to keystroke \"$1 && fg\\n\" '" > /dev/null 2>&1 &
    /bin/kill -SIGTSTP $kak_client_pid
    if [ ! -z "$2" ]; then
        echo "$2"
    fi
}}

def tig-blame -override -docstring 'Open blame in tig for current file and line' %{
    suspend-and-resume "tig blame +%val{cursor_line} %val{buffile}" 
}

Note: mine is customized to work os OSX. For linux change the nohup and kill lines to the following:

    nohup sh -c "sleep 0.2; xdotool type '$1'; xdotool key Return" > /dev/null 2>&1 &
    /usr/bin/kill -SIGTSTP $kak_client_pid

@Delapouite I think it’d make sense to have a wiki page that documents this generalized pattern for toggling back-and-forth between other cli apps. Then, modify your Ranger wiki page to link out to the generalized pattern, and include the ranger specific config. Mind if I make that change?


#9

You’re right, this suspend mechanism deserves its own wiki page.


#10

This is awesome. This is going to get so much use!


#11

Can somebody give me feedback on the updated wiki page I made - Integrating-Other-CLI-apps? I fear that I’m so familiar with this concept that I may have left out some important contextual information.

Also, can someone on linux give it a go? It should work, but I don’t have a running linux install to test on.

Once completed I think we’d just have the existing Ranger wiki page have a link to the subsection containing the examples of ranger integration.

Also feel free to edit the wiki page directly of course!


#12

Works for me on Linux, you forgot }} tho :wink:


#13

Good catch, thanks - I’ve fixed it on the wiki.


#14

Even though I used a different mechanism, this inspired me to solve a long-standing problem: I want new kakoune clients in tmux running under an interactive shell so they can be suspended.

I overrode tmux-terminal-impl to start a login shell and send keystrokes to start Kakoune, then exit after.

It’s still a bit wonky: If I suspend it to the shell then fg Kakoune again, the shell no longer exits if I quit Kakoune. If I never suspend Kakoune, it works.


#15

Fwiw you might be able to do that in a simpler way by changing the arguments to the terminal command, which should also work across each terminal backend. For example with bash

terminal bash -c 'bash --init-file <(echo "kak")'

The first bash -c call is to use the <() feature (which is not posix), the second is the actual interactive shell that gets run. Bash tip courtesy of this post, hopefully other shells have a similar (maybe even simpler) mechanism.

(this was supposed to be in reply to @eraserhd but apparently I don’t understand how those work on discourse)