{"action":"created","issue":{"url":"https://api.github.com/repos/fish-shell/fish-shell/issues/3477","repository_url":"https://api.github.com/repos/fish-shell/fish-shell","labels_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/3477/labels{/name}","comments_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/3477/comments","events_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/3477/events","html_url":"https://github.com/fish-shell/fish-shell/issues/3477","id":184161084,"number":3477,"title":"Something like a '{forward | backward}-process' and '{forward | backward}-delete-process' function for moving between pipes?","user":{"login":"Izzeri","id":10207684,"avatar_url":"https://avatars.githubusercontent.com/u/10207684?v=3","gravatar_id":"","url":"https://api.github.com/users/Izzeri","html_url":"https://github.com/Izzeri","followers_url":"https://api.github.com/users/Izzeri/followers","following_url":"https://api.github.com/users/Izzeri/following{/other_user}","gists_url":"https://api.github.com/users/Izzeri/gists{/gist_id}","starred_url":"https://api.github.com/users/Izzeri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Izzeri/subscriptions","organizations_url":"https://api.github.com/users/Izzeri/orgs","repos_url":"https://api.github.com/users/Izzeri/repos","events_url":"https://api.github.com/users/Izzeri/events{/privacy}","received_events_url":"https://api.github.com/users/Izzeri/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fish-shell/fish-shell/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-20T08:07:50Z","updated_at":"2016-10-24T07:11:40Z","closed_at":null,"body":"I often end up with a moderately long chain of piped commands, and then notice I want to make a change somewhere in the middle of the chain. I've been using forward/backward-word to speed up navigation, but it's often barely any faster than forward/backward-character. Yesterday I wrote a (admittedly super duper ugly) fish function for forward-pipe and backward-pipe that work pretty well, but it would be nice to have this functionality provided by default. I'd think it's pretty common to want to quickly navigate, say, 3 pipes backward in a command chain. My implementation uses `commandline -p` to get what process token the cursor is currently in, then `fgrep -aob` to get where that process is in the buffer, and then some awk magic to work around the case where there are two or more identical process tokens in the buffer. It would be nice if `commandline` could report at what position the process begins, maybe something like `commandline -pC`. Or if it could even say something like \"the cursor is in the third process, out of five processes\", and then say at what position in the buffer each process starts and ends.\r\n\r\nMy ugly functions (I'd be happy if someone could tell me my code is way too complicated):\r\n```\r\nfunction backward-pipe\r\n  set buf (commandline -b)\r\n  set curpos (commandline -C)\r\n\r\n  # if we are at the beginning of the buffer do nothing\r\n  if test $curpos -eq 0\r\n    return 0\r\n  end\r\n\r\n  set process (commandline -p)\r\n\r\n  # corner case if the process we are in is completely empty\r\n  if test $process = ''\r\n    commandline -C (math \"$curpos - 1\")\r\n    set process (commandline -p)\r\n  end\r\n\r\n  # find position of $process in $buf\r\n  # work around the case where there are multiple identical $process in $buf\r\n  set pipepos (echo $buf \\\r\n  | gfgrep -aob \"$process\" \\\r\n  | ggrep -oE \"[0-9]+:\" \\\r\n  | sed \"s/://\" \\\r\n  | awk -v t=$curpos \"NR==1{v=\\$1;next}{m=\\$1-t;if(m>0){exit;}else if(m==0){v=\\$1;exit}else{v=\\$1}}END{print v}\")\r\n\r\n  # if we end up at the same position, move backwards one character and try again\r\n  if test $pipepos -eq $curpos\r\n    commandline -C (math \"$pipepos - 1\")\r\n    backward-pipe\r\n  end\r\n\r\n  commandline -C $pipepos\r\nend\r\n\r\nfunction forward-pipe\r\n  set buf (commandline -b)\r\n  set buflen (echo (string length \"$buf\"))\r\n  set curpos (commandline -C)\r\n  if test $curpos -eq $buflen\r\n    return 0\r\n  end\r\n\r\n  set process (commandline -p)\r\n  set processlen (echo (string length \"$process\"))\r\n  set pipepos (echo \"$buf\" \\\r\n  | gfgrep -aob \"$process\" \\\r\n  | ggrep -oE \"[0-9]+:\" \\\r\n  | sed \"s/://\" \\\r\n  | awk -v t=$curpos \"NR==1{v=\\$1;next}{m=\\$1-t;if(m>0){exit;}else if(m==0){v=\\$1;exit;}else{v=\\$1}}END{print v}\")\r\n  if test (math \"$pipepos + $processlen + 1\") -eq $curpos\r\n    commandline -C (math \"$pipepos + $processlen + 2\")\r\n    forward-pipe\r\n  end\r\n\r\n  commandline -C (math \"$pipepos + $processlen + 1\")\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/fish-shell/fish-shell/issues/comments/255664358","html_url":"https://github.com/fish-shell/fish-shell/issues/3477#issuecomment-255664358","issue_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/3477","id":255664358,"user":{"login":"Izzeri","id":10207684,"avatar_url":"https://avatars.githubusercontent.com/u/10207684?v=3","gravatar_id":"","url":"https://api.github.com/users/Izzeri","html_url":"https://github.com/Izzeri","followers_url":"https://api.github.com/users/Izzeri/followers","following_url":"https://api.github.com/users/Izzeri/following{/other_user}","gists_url":"https://api.github.com/users/Izzeri/gists{/gist_id}","starred_url":"https://api.github.com/users/Izzeri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Izzeri/subscriptions","organizations_url":"https://api.github.com/users/Izzeri/orgs","repos_url":"https://api.github.com/users/Izzeri/repos","events_url":"https://api.github.com/users/Izzeri/events{/privacy}","received_events_url":"https://api.github.com/users/Izzeri/received_events","type":"User","site_admin":false},"created_at":"2016-10-24T07:11:40Z","updated_at":"2016-10-24T07:11:40Z","body":"I mainly agree with you, although I'm still biased towards wanting a clean way to do this without jumping into a real editor. The neat thing about writing shell oneliners is how quickly you can iterate your code. You write a snippet, hit enter, notice something didn't turn out right, go back one step in the history, make your changes, hit enter again, and so forth. Jumping into a real editor breaks this flow somewhat. Though I still completely understand your concerns, I just thought I'd provide another point of view on the issue!"}}
{"actor":{"display_login":"Izzeri"}}