{"action":"created","issue":{"url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/96","labels_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/96/labels{/name}","comments_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/96/comments","events_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/96/events","html_url":"https://github.com/christoomey/vim-tmux-navigator/issues/96","id":118293326,"number":96,"title":"Use process list to determine if Vim is active","user":{"login":"christoomey","id":420113,"avatar_url":"https://avatars.githubusercontent.com/u/420113?v=3","gravatar_id":"","url":"https://api.github.com/users/christoomey","html_url":"https://github.com/christoomey","followers_url":"https://api.github.com/users/christoomey/followers","following_url":"https://api.github.com/users/christoomey/following{/other_user}","gists_url":"https://api.github.com/users/christoomey/gists{/gist_id}","starred_url":"https://api.github.com/users/christoomey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christoomey/subscriptions","organizations_url":"https://api.github.com/users/christoomey/orgs","repos_url":"https://api.github.com/users/christoomey/repos","events_url":"https://api.github.com/users/christoomey/events{/privacy}","received_events_url":"https://api.github.com/users/christoomey/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-22T22:20:28Z","updated_at":"2015-12-04T12:40:01Z","closed_at":null,"body":"Currently we use a check of tmux's `pane_current_command` to determine if Vim is active. This has worked _just_ well enough, but is prone to a number of edge cases and false negatives.\r\n\r\nInstead, I want to look into another approach that would examine the process tree for the pane, and detect Vim that way.\r\n\r\nVia tmux's `{pane_pid}` format option to the `display-message` command we can get the parent pid of the pane. From there, we can use `pstree` to get the child process tree of the pane. The check is then if the current process (last element in `pstree` listing) is Vim.\r\n\r\nA rough, half-working version of this is:\r\n\r\n``` sh\r\nps -p $(tmux display-message -p -t 0 -F '#{pane_pid}' | xargs pstree | tail -1 | cut -d ' ' -f 3) -o comm=\r\n```\r\n\r\nThat outputs `/usr/local/Cellar/macvim/7.4-73_1/MacVim.app/Contents/MacOS/Vim` in my case, which could be matched agains for Vim checking\r\n\r\nLost to improve here (is `pstree` available?, better `sed` for getting the leaf pid, etc), but it's a start I think"},"comment":{"url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/comments/161957370","html_url":"https://github.com/christoomey/vim-tmux-navigator/issues/96#issuecomment-161957370","issue_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/96","id":161957370,"user":{"login":"patrickdepinguin","id":7582443,"avatar_url":"https://avatars.githubusercontent.com/u/7582443?v=3","gravatar_id":"","url":"https://api.github.com/users/patrickdepinguin","html_url":"https://github.com/patrickdepinguin","followers_url":"https://api.github.com/users/patrickdepinguin/followers","following_url":"https://api.github.com/users/patrickdepinguin/following{/other_user}","gists_url":"https://api.github.com/users/patrickdepinguin/gists{/gist_id}","starred_url":"https://api.github.com/users/patrickdepinguin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrickdepinguin/subscriptions","organizations_url":"https://api.github.com/users/patrickdepinguin/orgs","repos_url":"https://api.github.com/users/patrickdepinguin/repos","events_url":"https://api.github.com/users/patrickdepinguin/events{/privacy}","received_events_url":"https://api.github.com/users/patrickdepinguin/received_events","type":"User","site_admin":false},"created_at":"2015-12-04T12:40:01Z","updated_at":"2015-12-04T12:40:01Z","body":"On my Linux system, the pstree output is separated with 3 dashes, for example:\r\n\r\n    echo 4604 | xargs pstree \r\n    bash───xargs───vim\r\n\r\nTo get to vim, you can use the following command:\r\n\r\n    echo 4604 | xargs pstree | tail -1 | rev | cut -d- -f1 | rev\r\n\r\nThe first echo would obviously need to be replaced.\r\nAlternatively, since we're only interested in the last few characters being 'vim' (or derivative) or not, we could simply search for that string at the end, e.g.\r\n\r\n    echo 4604 | xargs pstree | grep 'vim$'\r\n"}}