{"action":"created","issue":{"url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/117","repository_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator","labels_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/117/labels{/name}","comments_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/117/comments","events_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/117/events","html_url":"https://github.com/christoomey/vim-tmux-navigator/pull/117","id":146893751,"number":117,"title":"Look for vim with ps/awk","user":{"login":"blueyed","id":9766,"avatar_url":"https://avatars.githubusercontent.com/u/9766?v=3","gravatar_id":"","url":"https://api.github.com/users/blueyed","html_url":"https://github.com/blueyed","followers_url":"https://api.github.com/users/blueyed/followers","following_url":"https://api.github.com/users/blueyed/following{/other_user}","gists_url":"https://api.github.com/users/blueyed/gists{/gist_id}","starred_url":"https://api.github.com/users/blueyed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blueyed/subscriptions","organizations_url":"https://api.github.com/users/blueyed/orgs","repos_url":"https://api.github.com/users/blueyed/repos","events_url":"https://api.github.com/users/blueyed/events{/privacy}","received_events_url":"https://api.github.com/users/blueyed/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-04-08T11:00:20Z","updated_at":"2016-04-13T15:39:03Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/pulls/117","html_url":"https://github.com/christoomey/vim-tmux-navigator/pull/117","diff_url":"https://github.com/christoomey/vim-tmux-navigator/pull/117.diff","patch_url":"https://github.com/christoomey/vim-tmux-navigator/pull/117.patch"},"body":"This looks for PIDs using ps/awk, ignores a stopped Vim and its childs.\r\n\r\nBased on the idea in #96.\r\n\r\nTODO\r\n - [ ] try to get rid of awk for performance reasons (`sed`/`cut` would be faster probably), or use a single `awk` invocation/script, which seems to be possible here (maybe also with `sed` even?!).\r\n\r\nLeaving this here for reference, in case it might become necessary later:\r\n\r\n    # Get last pid in list, without childs of Vim or stopped processes.\r\n    # \"T zsh\" would be in there after (Neo)vim after \"Ctrl-Z\" and \"fg\".\r\n    last_wo_vim_childs=\"$(echo \"$session_childs\" \\\r\n      | awk \"\\$2 != $vim_pid && \\$1 != $$ && \\$2 != $$ && \\$3 !~ /T/ {print \\$1}\" \\\r\n      | tail -n1)\"\r\n\r\n    # We've filtered Vim's process group, so should end up at the pane_pid.\r\n    test \"$last_wo_vim_childs\" -eq \"$1\" 2>/dev/null\r\n"},"comment":{"url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/comments/209516087","html_url":"https://github.com/christoomey/vim-tmux-navigator/pull/117#issuecomment-209516087","issue_url":"https://api.github.com/repos/christoomey/vim-tmux-navigator/issues/117","id":209516087,"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},"created_at":"2016-04-13T15:39:03Z","updated_at":"2016-04-13T15:39:03Z","body":"@blueyed & @keith thanks for looking into this!\r\n\r\n@blueyed, I get an error on OS X with the `ps o state:1=,comm=` invocation.\r\n\r\nI'm having some luck with the following script though:\r\n\r\n``` sh\r\n#!/bin/sh\r\n\r\npid=$(tmux display-message -t \"$1\" -p '#{pane_pid}')\r\ntty=$(ps -p \"$pid\" | tail -1 | cut -d ' ' -f 3)\r\nprocess=$(ps -t \"$tty\" | tail -n +2 | cut -d ' ' -f 8 | tail -1)\r\n\r\necho \"$process\" |  grep -iqE \"(^|\\/)g?(view|n?vim?x?)(diff)?$\"\r\n```\r\n\r\nSome inconsistency between output that I'm battling, but heading in the right direction. I'll poke more later this week."}}