I’d like to set up my Bash in such a way that I could yank text from the previous command’s stdout. The example use case I’ll use is resolving conflicts during a git rebase.
$ git status
# Not currently on any branch.
# Unmerged paths:
# (use "git reset HEAD <file>..." to unstage)
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: app/views/report/index.html.erb
#
$ vim app/views/report/index.html.erb
# .... edit, resolve conflicts ....
$ git add <Alt+.>
The problem is that the easiest way to grab the filename for the 2nd command (vim ...) is to move my hand over to the mouse. One option is screen, but that has its own set of issues as a day-to-day shell. (Not the least of which is that I use and abuse Ctrl+A as a readline shortcut)
Where could I start at making this work for me? Ideally I’d like to be able to pull the Nth line from the stdout of the previous command somewhere that I can manipulate it as a command.
Other than using the mouse, the only way I can think of is to use
grep,sedand/orawk, perhaps withteeand/or a Bash function and process substitution and/or process and/or command substitution:or
The
teeallows you to see the full output while capturing the modified output. Creating a function would allow you to easily pass an argument that would select a certain line:The disadvantage is that you have to do this from the start. I don’t know of any way to do this after the fact without using
screenor some other output logging and scripting a rummage through the log.