Merging files in Sublime with Sublimerge via command line - merge

I'm trying to find a better merge file option and wanted to try out Sublime as of my work is done using it. so I installed Sublimerge and now am stuck. I know I can compare two already open files or compare via the Sidebar but what I want to do is fire it off via the command line so I can kick it off from our source control program like I can with every other merge tool I've seen. Does anyone know the command line format to do this?
N.B. - I've long since given up trying to use sublime to handle merges and instead switched to other tools to handle this. Therefore I've never felt I can accept any answer as I'm not checking them to see if they work in the way I'd want, or indeed whether they work at all.

subl -n --wait "<LEFT>" "<RIGHT>" --command "sublimerge_diff_views {\"left_read_only\": true, \"right_read_only\": true}"
See "VCS Integration" for details.

As Nickolay already suggested, this is the whole directive you have to put in your ~/.gitconfig:
[merge]
tool = sublimerge
[mergetool "sublimerge"]
cmd = subl -n --wait \"$REMOTE\" \"$BASE\" \"$LOCAL\" \"$MERGED\" --command \"sublimerge_diff_views\"
trustExitCode = false
[diff]
tool = sublimerge
[difftool "sublimerge"]
cmd = subl -n --wait \"$REMOTE\" \"$LOCAL\" --command \"sublimerge_diff_views {\\\"left_read_only\\\": true, \\\"right_read_only\\\": true}\"

Taking jnns' answer, but making appropriate changes for windows.
%USERPROFILE%\.gitconfig:
[merge]
tool = sublimerge
[mergetool "sublimerge"]
cmd = sublime_text -n --wait \"$REMOTE\" \"$BASE\" \"$LOCAL\" \"$MERGED\" --command \"sublimerge_diff_views\"
trustExitCode = false
[diff]
tool = sublimerge
[difftool "sublimerge"]
cmd = sublime_text -n --wait \"$REMOTE\" \"$LOCAL\" --command \"sublimerge_diff_views {\\\"left_read_only\\\": true, \\\"right_read_only\\\": true}\"
note location of .gitconfig
in windows, the executable is sublime_text.exe, NOT subl
don't forget to add sublime text executable to the path

I'm not sure exactly how to do it, but I'm getting closer.
First, you need a handy path to the Sublime binary:
mkdir ~/bin
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Then, in your git GUI or git command line, configure ~/bin/subl as your merge tool.
I use Source Tree, and I haven't figured exactly how to best use Sublimerge, but I managed to open both versions, merge them, and then I have to do a bit of manual work.
Still not smooth, but better than nothing!

Related

How to solve CTRL-t key binding issue for fzf?

I recently found this command line tool called fzf. I installed it according to the instructions and it does work, except for the CTRL-T key binding. Even though, I installed the special stuff with the key bindings as per their instructions, and I also tried installing fzf downloaded from the git repo as opposed to via homebrew, all the CTRL-T key binding does, still, is swap the last two characters.
I found this discussion about this, but none of the answers offered worked for me.
edit: you can see it in the first video here what I want to achieve.
edit 2: I'm using the Terminal of MacOs.
I use zsh with Oh My Zsh on Mac.
If I put fzf before vi-mode in the plugin setting in .zshrc like
plugins=(... fzf ... vi-mode ...)
Ctrl-t does not work showing ^T. Ctrl-r does not work, either.
But, if fzf comes AFTER vi-mode like
plugins=(... vi-mode ... fzf ...)
no problem arises.
If you clone fzf from the repository it contains a file called fzf/shell/key-bindings.zsh which refers to
fzf-file-widget() {
LBUFFER="${LBUFFER}${__fsel}"
local ret=$?
zle redisplay
typeset -f zle-line-init >/dev/null && zle-line-init
return $ret
}
zle -N fzf-file-widget
bindkey "^T" fzf-file-widget
the Control-T keybinding. This is normally sourced by your .zshrc
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
which should contain its reference in .fzf.zsh:
source "$HOME/.fzf/shell/key-bindings.zsh"
If your keybinding does not work then your keybinding may be overwritten by your zshrc or may not be invoked by your zshrc.
If you are using zsh-vi-mode, then replace this line
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
with this
zvm_after_init_commands+=('[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh')
From zsh-vi-mode GitHub page
Psst! if you use fzf-tab, you might want to enable that also
zvm_after_init_commands+=('[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh && enable-fzf-tab')
I put the below script in my .zshrc and sourced it using source ~/.zshrc
if [ -x "$(command -v fzf)" ]
then
source /usr/share/fzf/key-bindings.zsh
fi
and now key bindings (CTRL-T, CTRL-R, and ALT-C) work for me.
got the above script from how to enable hotkeys for fzf
explanation
you have key-bindings.zsh inside /usr/share/fzf or a few directories deeper.
Above script only sources key-bindings.zsh if fzf is installed.
rest of the working is part of the key-bindings.zsh, which frankly I did not bother to
understand.
OS: Manjaro GNU-Linux
I have noticed CTRL-T does not work (in bash) when I have the "vi mode" enabled by set -o vi.
I managed to make the CTRL-t key combo work as desired. There was one step I had missed.
After installing useful keybindings and fuzzy completion with /usr/local/opt/fzf/install, I updated fzf.bash manually with [ -f ~/.fzf.bash ] && source ~/.fzf.bash. After restarting the Terminal, it now works.
Edit: Also, this line needs to be added to your .bash_profile or .bashrc: source ~/.fzf.bash.

How do I use Meld as a merge tool with Sourcetree on Windows?

I have the following in my .gitconfig file:
[user]
name = myname
email = myname#gmail.com
[core]
autocrlf = true
excludesfile = C:\\Users\\myname\\Documents\\gitignore_global.txt
[diff]
tool = meld
[difftool "meld"]
cmd = "C:/Program Files (x86)/Meld/meld/meld.exe"
prompt = false
[merge]
tool = meld
[mergetool "meld"]
cmd = "C:/Program Files (x86)/Meld/meld/meld.exe"
[difftool "sourcetree"]
cmd = "C:/Program Files (x86)/Meld/meld/meld.exe $PWD/$LOCAL $PWD/$BASE $PWD/$REMOTE"
[mergetool "sourcetree"]
cmd = 'C:/Program Files (x86)/Meld/meld/meld.exe' \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
trustExitCode = true
And in Sourcetree, I have the following settings:
However, when I right-clicked a file on Sourcetree to do an external diff, I was able to open Meld, but the contents of the file were not displayed at all.
What have I done wrong in the settings?
I feel the existing answers slightly missed the point. Here is my own dog food:
Arguments Detail:
Diff: $LOCAL $REMOTE
Merge: $LOCAL $BASE $REMOTE --auto-merge --output=$MERGED
For External Diff, you need to remove $BASE from your argument list.
For 3-way merging, you need to click on the External Merge Tool option instead, which will only be available if there are any unsolved conflicts.
If you are not restricted to Sourcetree + Meld, I reckon the Git Extensions + KDiff3 suite could be a good open-sourced alternative also.
The actual setting to use here in order to have a real 3-way merge, with read only THEIRS and MINE tabs is this:
$LOCAL $BASE $REMOTE --auto-merge --output=$MERGED
Note the = after --output.
I've finally got this command right by digging in comments on the second answer to this question Git merging using Meld.
For OS X it looks like this:
Diff Command: /Applications/Meld.app/Contents/MacOS/meld.
Arguments: $LOCAL $REMOTE
Merge Command: /Applications/Meld.app/Contents/MacOS/meld.
Arguments: $LOCAL $BASE $REMOTE --auto-merge --output=$MERGED
P.S.
you might have to configure the order of $local and $ remote in meld prefrences as well..
To use it from command line you have to install it via brew:
brew install meld
Try adding the location of meld.exe to your PATH (e.g. C:\Program Files (x86)\Meld), and then in the Diff Command, just enter meld instead of the full path. See the gist How to use meld with Sourcetree on Windows.
If you don't want to modify the PATH environment variable, you can use the DOS-compatible short names:
C:\Progra~1 = C:\Program Files
C:\Progra~2 = C:\Program Files (x86)
That avoids the trouble-causing spaces in the path and plays nice with Sourcetree. It's hackish, but it works. You can then use something like this as the path to Meld:
C:\Progra~1\Meld\meld.exe
It may not be guaranteed that Progra~1 maps to the 64-bit directory, so you might need to experiment with which one maps to which.

launch sublime text 3 in terminal with zsh

I recently purchased a new MacBook and I am trying to re-configure my system.
The app is inside the Applications folder as 'Sublime Text.app'
I have edited the sublime.plugin.zsh file via other advice I found online to 'Sublime Text 3.app' as well as 'Sublime Text.app' with no luck on either:
elif [[ $('uname') == 'Darwin' ]]; then
local _sublime_darwin_paths > /dev/null 2>&1
_sublime_darwin_paths=(
"/usr/local/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
)
for _sublime_path in $_sublime_darwin_paths; do
if [[ -a $_sublime_path ]]; then
alias subl="'$_sublime_path'"
alias st=subl
break
fi
done
fi
alias stt='st .'
I still get
zsh: command not found: st
I am simply at a loss on where to go next
I had the same problem with zsh and this did the job:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Then you launch a open a file my_file.txt with Sublime:
subl ./my_file.txt
Don't specify any file if you just want to open Sublime. I hope this helps ;)
First, try to first launch the sublime binary manually (interactively) via zsh.
To do that, you'll have to discover where this binary is. There are two practical options here, choose what you are most comfortable with:
Check manually those listed binaries, see which of them exist.
Slightly modify your script to echo something inside your if:
if [[ -a $_sublime_path ]]; then
echo "Sublime found: $_sublime_path"
alias subl="'$_sublime_path'"
alias st=subl
break
fi
After finding the correct one, create the st alias in your .zshrc file:
alias st="/correct/path/to/subl"
If you don't find anything in the first step, then your original script is really not supposed to work.
Just moved to App in mac
Check your current path
echo $PATH
Add a sym link from Sublime App to one of your path. Choose /usr/local/bin for example
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime
Then back to terminal and run sublime. You should be open the sublime through terminal
To setup alias for mac users;
open ~/.zshrc using the below command
vi ~/.zshrc
Add the following alias
alias subl="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'"
run subl . command should work properly.
Official documentation: https://www.sublimetext.com/docs/command_line.html#mac
ZSH
If using Zsh, the default starting with macOS 10.15, the following command will add the bin folder to the PATH environment variable:
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile

How to set xterm-256colors on iTerm2 via script / command line

In iTerm2 we can set the xterm-256color option by going to Preferences -> Profiles -> Terminal -> Terminal Emulation -> Report Terminal Type and chosing xterm-256color
I want to add to my dotfile's installation script so I don't have to change it manually.
Is there a way of setting this option via command line? Maybe via iTerm itself or maybe via apple's defaults write.....
Thank you!
default works only if the setting is a top level key, for example
[admin#mb-125:~] : defaults read com.googlecode.iterm2 | grep -i promptonquit
PromptOnQuit = 1;
[admin#mb-125:~] : defaults write com.googlecode.iterm2 PromptOnQuit -bool FALSE
[admin#mb-125:~] : defaults read com.googlecode.iterm2 | grep -i promptonquit
PromptOnQuit = 0;
xterm-256color is part of a dictionary, and we need to use plistbuddy to change it, here is the command to see the current settings
[admin#mb-125:~] : /usr/libexec/PlistBuddy -c "Print :\"New Bookmarks\":0:\"Terminal Type\"" Library/Preferences/com.googlecode.iterm2.plist
xterm-256color
And this is how you change it from command line
[admin#mb-125:~] : /usr/libexec/PlistBuddy -c "Set :\"New Bookmarks\":0:\"Terminal Type\" xterm" Library/Preferences/com.googlecode.iterm2.plist
[admin#mb-125:~] : /usr/libexec/PlistBuddy -c "Print :\"New Bookmarks\":0:\"Terminal Type\"" Library/Preferences/com.googlecode.iterm2.plist
xterm
In the ~/Library/Preferences folder there's a file called com.googlecode.iterm2.plist. This file contains all your iTerm preferences. What I like to do is keep a copy of that preferences file inside my dotfile repo. When I'm installing on a new system I copy it into ~/Library/Preferences via my installation script .
Hope that helps!

Cygwin shortcut for command history

How can I search the command history in cygwin?
I don't want to keep pressing the arrow keys to execute a command from console command history.
If you are using the default editing mode, do ctrl+R to search back through your history.
If you have done set -o vi to use vi editing mode, then it is esc-/
The history command is the way to go. I use
h ()
{
history | cut -f 2- | sort -u | grep -P --color=auto -e "$*"
}
so that I can type something like h git.*MyProgram, h ^tar -c, h svn:ignore, etc to pull up a sorted list of past commands matching a regex.
You might also want to add the following lines to ~/.inputrc:
# Ctrl+Up/Down for searching command history
"\e[1;5A": history-search-backward
"\e[1;5B": history-search-forward
With these in place, you can type a partial command prefix (such as gi or sql) then use Ctrl+Up to scroll back through the list of just your command history entries that match that prefix (such as git clone https://code.google.com/p/double-conversion/ and sqlite3 .svn/wc.db .tables). This can be a lot faster than searching and then cutting and pasting if you want to edit or re-execute a command that was fairly recent.
I use the history command in combination with grep, e.g. history | grep vi shows all commands where vi was used.
Checkout the "Gnu Bash Manual" (man bash) for the command "fc". E.g.fc -l -80 would list the last 80 commands, while other options let you search with RegEx...
Do
vi ~/.inputrc
Add
For arrow up/down bindings:
"\e[A": history-search-backward
"\e[B": history-search-forward
Or for page up/down bindings:
"\e[5~": history-search-backward
"\e[6~": history-search-forward
Close and open cygwin.
Voila.
I think one of the easiest way is to pipeline it with less and press search character ("/") and then type the command you wanna find.
history | less
and then
/text to find
to find the desired command
Another way
is to append the stdout form history command to a file: history > /cygdrive/path/file.txt
and then search in the document.