Artificial intelligent assistant

Supply the same filename as argument to two commands On a git conflict, I can currently do: git diff path/to/some/file.txt ... after reviewing the diff, usually I want to do: git checkout --theirs path/to/some/file.txt && git add path/to/some/file.txt It's painstaking to edit both paths each time, so I'd like to be able to do the following: git checkout --theirs <ref> && git add path/to/some/file.txt Where the `<ref>` refers to file.txt. Any way to do this in bash?

There are many ways.

You can use history expansion in (t)csh, bash or zsh. `!$` expands to the last argument of the previous command line.


git checkout --theirs !$ && git add !$


Bash, ksh and zsh have a variable `$_` which stores the last argument of the last simple command executed by the shell.


git checkout --theirs "$_" && git add "$_"


Bash and zsh have a keyboard shortcut `Alt`+`.` or `ESC` `.` which inserts the last argument of the previous command line.


git checkout --theirs Alt+. && git add Alt+.


You can stuff this in a function.


git_add_theirs () {
if [ "$#" -eq 0 ]; then set -- "$_"; fi
git checkout --theirs -- "$@" && git add -- "$@"
}


Or make that a standalone script and define an alias `add-theirs = git_add_theirs` in your `~/.gitconfig`.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy f2a602ce6202bc2627e536964be2b4b4