# Running tig?

**URL:** <https://discuss.kakoune.com/t/running-tig/144>\
**Category:** Help\
**Tags:** git\
**Created:** [October 28, 2018, 5:43pm UTC](https://discuss.kakoune.com/t/running-tig/144 "2018-10-28T17:43:16Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [October 28, 2018, 5:43pm UTC](https://discuss.kakoune.com/t/running-tig/144/1 "2018-10-28T17:43:16Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Delapouite](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/delapouite/32/10_2.png) [@Delapouite](https://discuss.kakoune.com/u/Delapouite)\
**Post date:** [October 29, 2018, 10:43pm UTC](https://discuss.kakoune.com/t/running-tig/144/2 "2018-10-29T22:43:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [October 30, 2018, 10:46am UTC](https://discuss.kakoune.com/t/running-tig/144/3 "2018-10-30T10:46:45Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![xyuusha](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/xyuusha/32/48_2.png) [@xyuusha](https://discuss.kakoune.com/u/xyuusha)\
**Post date:** [November 5, 2018, 5:21am UTC](https://discuss.kakoune.com/t/running-tig/144/4 "2018-11-05T05:21:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [November 7, 2018, 10:02pm UTC](https://discuss.kakoune.com/t/running-tig/144/5 "2018-11-07T22:02:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![schickm](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schickm/32/79_2.png) [@schickm](https://discuss.kakoune.com/u/schickm)\
**Post date:** [January 25, 2019, 4:46pm UTC](https://discuss.kakoune.com/t/running-tig/144/6 "2019-01-25T16:46:20Z")

</div>

I use the same [pattern recommended for ranger integration](https://github.com/mawww/kakoune/wiki/Ranger), 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.

---

<div class="post-metadata">

**Author:** ![supermarin](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/supermarin/32/71_2.png) [@supermarin](https://discuss.kakoune.com/u/supermarin)\
**Post date:** [January 29, 2019, 4:41am UTC](https://discuss.kakoune.com/t/running-tig/144/7 "2019-01-29T04:41:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![schickm](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schickm/32/79_2.png) [@schickm](https://discuss.kakoune.com/u/schickm)\
**Post date:** [January 29, 2019, 12:48pm UTC](https://discuss.kakoune.com/t/running-tig/144/8 "2019-01-29T12:48:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Delapouite](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/delapouite/32/10_2.png) [@Delapouite](https://discuss.kakoune.com/u/Delapouite)\
**Post date:** [January 29, 2019, 1:58pm UTC](https://discuss.kakoune.com/t/running-tig/144/9 "2019-01-29T13:58:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [February 2, 2019, 1:59am UTC](https://discuss.kakoune.com/t/running-tig/144/10 "2019-02-02T01:59:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![schickm](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schickm/32/79_2.png) [@schickm](https://discuss.kakoune.com/u/schickm)\
**Post date:** [February 2, 2019, 5:21pm UTC](https://discuss.kakoune.com/t/running-tig/144/11 "2019-02-02T17:21:53Z")

</div>

Can somebody give me feedback on the updated wiki page I made - [Integrating-Other-CLI-apps](https://github.com/mawww/kakoune/wiki/Integrating-Other-CLI-apps-(Work-in-Progress))? 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](https://github.com/mawww/kakoune/wiki/Ranger) have a link to the [subsection](https://github.com/mawww/kakoune/wiki/Integrating-Other-CLI-apps-(Work-in-Progress)#ranger) containing the examples of ranger integration.

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

---

<div class="post-metadata">

**Author:** ![TeddyDD](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/teddydd/32/21_2.png) [@TeddyDD](https://discuss.kakoune.com/u/TeddyDD)\
**Post date:** [February 2, 2019, 8:50pm UTC](https://discuss.kakoune.com/t/running-tig/144/12 "2019-02-02T20:50:18Z")

</div>

Works for me on Linux, you forgot `}}` tho 😉

---

<div class="post-metadata">

**Author:** ![schickm](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/schickm/32/79_2.png) [@schickm](https://discuss.kakoune.com/u/schickm)\
**Post date:** [February 2, 2019, 9:06pm UTC](https://discuss.kakoune.com/t/running-tig/144/13 "2019-02-02T21:06:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eraserhd](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/eraserhd/32/15_2.png) [@eraserhd](https://discuss.kakoune.com/u/eraserhd)\
**Post date:** [February 3, 2019, 4:49pm UTC](https://discuss.kakoune.com/t/running-tig/144/14 "2019-02-03T16:49:01Z")

</div>

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.

> <https://github.com/eraserhd/dotfiles/blob/develop/kak/config/kak.symlink/kakrc#L265-L285>

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.

---

<div class="post-metadata">

**Author:** ![occivink](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/occivink/32/27_2.png) [@occivink](https://discuss.kakoune.com/u/occivink)\
**Post date:** [February 3, 2019, 8:15pm UTC](https://discuss.kakoune.com/t/running-tig/144/15 "2019-02-03T20:15:51Z")

</div>

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

```auto
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](https://serverfault.com/questions/368054/run-an-interactive-bash-subshell-with-initial-commands-without-returning-to-the), 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)
