-
-
Save dersam/0ec781e8fe552521945671870344147b to your computer and use it in GitHub Desktop.
## Open GitKraken using the current repo directory. | |
## For when you want a prettier view of your current repo, | |
## but prefer staying in the cli for most things. | |
## This will break if GitKraken ever removes the -p flag. | |
## If you're not using OSX, the path is definitely different. | |
kraken () { | |
~/Applications/GitKraken.app/Contents/MacOS/GitKraken -p $(pwd) | |
} | |
# If you want a git alias, add the following to your git config under [alias] | |
kraken = !"~/Applications/GitKraken.app/Contents/MacOS/GitKraken -p $(pwd)" | |
# Now you can 'git kraken'! |
@krenor i copied the alias to my .zshrc file but it didn't work
@sgates 's solution works for me. I'm using the latest macOS and zsh.
For some reason, when using the alias, if GitKraken is not already open, it freezes my computer for ~10s while it seems to open. Anyone else experiencing this?
Here's a powershell function in case anybody wants:
function krak() {
$curpath = (get-location).ProviderPath
$lapd = $env:localappdata
$logf = "$env:temp\krakstart.log"
start-process -filepath "$lapd\gitkraken\app-4.0.2\gitkraken.exe" -ArgumentList "--path $curpath" -redirectstandardoutput $logf
}
I get a few node event log entries printed to stdout from that, which is annoying but livable.
Thanks @rpardee. A made a small change to the Powershell Function to always use the lastest version of gitkraken.exe
# Open Git Kraken
function krak() {
$curpath = (get-location).ProviderPath
$lapd = $env:localappdata
$logf = "$env:temp\krakstart.log"
$newestExe = Get-Item "$lapd\gitkraken\app-*\gitkraken.exe" | select -Last 1
start-process -filepath $newestExe -ArgumentList "--path $curpath" -redirectstandardoutput $logf
}
Reminder: if you add this function to %userprofile%\documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
it will always be in available in your PowerShell console.
This will always pass the root of the current git repo to GitKraken
alias kraken='open -na "GitKraken" --args -p $(git rev-parse --show-toplevel)'
Thanks @seanhoughton . Here's a slight modification so that it will work even if the path has spaces:
alias kraken='open -na GitKraken --args -p "$(git rev-parse --show-toplevel)"'
Note to readers: open(1) is a macOS command.
For Linux (Ubuntu):
alias kraken='eval "gitkraken --new-window -p `pwd` -l /dev/null >/dev/null 2>&1 &"'
Thanks @karlwilbur, but one small gripe: this doesn't work for paths with spaces. This works, however:
alias kraken='eval "gitkraken --new-window -p \"`pwd`\" -l /dev/null >/dev/null 2>&1 &"'
Are these still working for you when GitKraken is already running? All that happens here is that GitKraken becomes the active window, but no repo is opened. It works fine if GitKraken is not running when I invoke the command.
Thanks for this, I was able to take this one step further:
alias kraken="open -a 'GitKraken' --args -p $(pwd)"
- this will preserve one indow, but works only for one repo. It will not open new repos.
This will keep it from "running" in the terminal, and if you want to be able to spawn multiple instances (to have multiple side by side repos open), add and 'n':
alias kraken="open -na 'GitKraken' --args -p $(pwd)"
- this opens a new kraken instance for each repo.
Is there any solution to open new repo in new tab of same instance?
Update:
in order to support spaces in the path, wrap double quotes around:
here is a single line to add kraken suppoet in .zshrc
:
# Now you can 'git kraken'!
alias kraken='open -na "GitKraken" --args -p "$(git rev-parse --show-toplevel)"'
https://gist.github.com/skywinder/39d4d0708d291f40a97d45e82653f127
in the gist is typo with function path.
here is right version
kraken () {
/Applications/GitKraken.app/Contents/MacOS/GitKraken -p "$(git rev-parse --show-toplevel)" &>/dev/null &
}
Both of version got an issue with path renderings. here is my updated version, btw
https://gist.github.com/skywinder/39d4d0708d291f40a97d45e82653f127
Enjoy!
I happened to typo this and found a workaround that works with GitKraken 7.1.0 - I added a blank (''
, but can be anything) argument before the -p 'PATH'
. I'm going to guess it has to do with argument parsing that GK is doing and they are stripping too many arguments before beginning parsing. My current git alias:
kraken = !open -na "GitKraken" --args '' -p "$(cd "${1:-.}" && git rev-parse --show-toplevel) && open -a GitKraken; :"
Thanks @karlwilbur, but one small gripe: this doesn't work for paths with spaces. This works, however:
alias kraken='eval "gitkraken --new-window -p \"`pwd`\" -l /dev/null >/dev/null 2>&1 &"'
A small tweak in the end to bring GitKraken window on Focus
# Open GitKraken using the current repo directory in the cli and bring it on focus.
alias kraken='eval "gitkraken --new-window -p \"`pwd`\" -l /dev/null >/dev/null 2>&1 &" && eval "wmctrl -R GitKraken"'
# Now you can 'kraken'!
The new url schema works better for me, I couldn't get any suggestions above to work with GitKraken 7.3.2.
So the idea is that GitKraken automatically installs an URI-schema handler in MacOS that handles URIs that start with gitkraken://
From the docs I learned that the first path component is a directive, so opening a repo is just the directive "repo", so if I have my repo at "/Users/myuser/git/InterestingGitRepo", the terminal command is plainly
open gitkraken://repo/Users/myuser/git/InterestingGitRepo
which opens my repo in a new tab in GitKraken.
So in terms of the aliases in this thread, you could use this:
# Open GitKraken using the current repo directory in the cli and bring it on focus.
alias kraken='open gitkraken://repo/$PWD'
Thanks @hlynbech for that tip - I totally missed the gitkraken://
scheme. I've updated my ~/.gitconfig
with the following:
[alias]
kraken = !open "gitkraken://repo$(cd "${1:-.}" && git rev-parse --show-toplevel); :"
Note that it works regardless of the directory you are in, even if some subdir within your clone, and allows you to specify some other directory on the command line.
Thanks @hlynbech! I've tried a few things from this thread and yours was the only one that worked for me.
In case anyone coming from Google is wondering, I'm using MacOS Mojave and Zsh.
Yes, @hlynbech url scheme approach is working here too.
Slight update for anyone who cares - if you happen to have a subrepo or other git-repo inside of another repo this requires a slight fix to use the current working directory instead of just the root of the current repository, so this is my current alias:
kraken = !open "gitkraken://repo$(cd "${GIT_PREFIX:-.}/${1:-.}" && git rev-parse --show-toplevel); :"
I liked Sourcetree's stree foo
on Mac. Similarly krak
opens a repo dir passed as arg:
krak () {
dir="$(cd "$(dirname "$1")"; pwd -P)/$(basename "$1")"
open gitkraken://repo/$dir
}
Is there any way to open a folder in an already open instance of Gitkraken? I'm on Linux
I've ended up with this zsh alias, but, I guess, that would work elsewhere:
alias gk='(eval "gitkraken --new-window -p \"$(git rev-parse --show-toplevel)\" -l /dev/null >/dev/null 2>&1 &")'
It's based on solution from older commends, but:
- It uses
(
and)
to hide the printing of PID process, thats printed by kernel if you use&
— thats why I decided to write the comment. - It uses
--new-window
to open repo, if gitkraken already launched somewhere. - It uses
git rev-parse --show-toplevel
and not pwd to get repository right - It uses black magic
-l /dev/null >/dev/null 2>&1 &
to hide all the shit and logs.
@pablogs9 use --new-window
. Yea, it's not that obvious.
--new-window
works like charm!
https://gist.github.com/dersam/0ec781e8fe552521945671870344147b#gistcomment-3453223
I made this Quick Action using your logic, it worked just fine
I will share to you the exported files:
Link: https://github.com/rbatty19/mac-os-automators/
more info:
https://stackoverflow.com/questions/70815538/open-with-shortcut-quick-action-for-vs-code-git-kraken
https://stackoverflow.com/questions/64040393/open-a-folder-in-vscode-through-finder-in-macos
I added this to my .bashrc
and it works like a charm in any directory inside a git repo you might be
function kraken() {
open -na 'GitKraken' --args -p $(git rev-parse --absolute-git-dir)
}
I added this to my
.bashrc
and it works like a charm in any directory inside a git repo you might befunction kraken() { open -na 'GitKraken' --args -p $(git rev-parse --absolute-git-dir) }
work to me
to anyone else who stumbles on this. to handle dirs with spaces:
alias kraken="open -na 'GitKraken' --args -p \"$(git rev-parse --absolute-git-dir)\""
alias gk="kraken"
For me the alias didn't work using zsh due to shell expansion. You'll have to switch the quotes:
alias kraken='open -na "GitKraken" --args -p $(pwd)'