Code Monkey home page Code Monkey logo

git-open's Introduction

Oi ๐Ÿ‘‹

I've been writing software since 2012, and I think I am starting to understand it โšก

I write anything interesting that comes to mind on my blog.

Not a fan of the "how-to" wave we are currently in, how to get rich, how to get smart, how to get fit, etc.

I love everything slow.

git-open's People

Contributors

caruccio avatar filewalkwithme avatar gerep avatar jdickey avatar justinaiken avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-open's Issues

Branches?

It would be really cool if the Github repo shown in the browser was for the branch currently active in the terminal window. As it is, opengit will by default open the master branch (or other default if you've set it manually).

Note that this is different than the existing opengit remote-branch syntax, in that the new default would be the (appropriate) remote branch matching the current local branch; if you were on a branch and wanted to open master, then use opengit master.

Implement branch autocomplete

I was trying to find a way of adding an autocomplete script to a subcommand but I couldn't find a way.

Reading the git-completion.bash I noticed that it has a pattern for the function names. For instance _git_stash().

So it came to me and I created the function _git_open() and it works perfectly!

This is a temporary proposal: (this is inside my .profile)

function _git_open()
{
	local word=${COMP_WORDS[COMP_CWORD]}
	COMPREPLY=($(compgen -W "$(git branch -r)" -- "${word}"))

}

complete -F _git_open git-open

The only downside so far is that it lists only remote branches.

When testing local branches with COMPREPLY=($(compgen -W "$(git branch | sed)" -- "${word}")), for some reason, it was also listing the files and directories.

feature suggestions

After using hub browse for a while, which does a similar job, I wrote this:

#!/bin/bash

branch=$(git name-rev --name-only HEAD)
if [ -z "$branch" ]; then
  echo >&2 "Cannot determine branch. Detached head? Using 'master'"
  branch="master"
fi
tracking_remote=$(git config branch.$branch.remote)
if [ -z "$tracking_remote" ]; then
  echo >&2 "No remote branch found for branch $branch. Using 'origin'"
  tracking_remote="origin"
fi
remote_url=$(git config remote.$tracking_remote.url)
if [ -z "$remote_url" ]; then
  echo >&2 "No remote url found for remote $tracking_remote."
  exit 1
fi

remote=$(echo "$remote_url"|sed -e 's/git@/http:\/\//;s/net:/net\//;s/.git$//')
commit=$(git --no-pager log -n1 --pretty=format:%H)
if [ -n "$1" ] ; then
  path="blob/$commit/$1"
else
  path="tree/$commit"
fi
if [ -n "$2" ] ; then
  start="#L$2"
fi
if [ -n "$3" ] ; then
  end="-L$3"
fi
open "$remote/$path$start$end"

... my use case was usually to share a link to a specific file or lines from a file to a slack room, so my script ('gitlink') took a file and optionally line numbers as args. I pick up the current branch instead of taking a branch as an arg. I also link to a specific commit instead of the branch, to prevent historical links bitrotting. Anyway, feel free to use/ignore any of this.

Not working for BitBucket

It's opening the url https://bitbucket.org/https://ericbiewener@bitbucket/branch/master, which isn't valid.

Function `opengit` is Linux-specific

Namely, it uses xdg-open, which is a common (Arch/Ubuntu/others) Linux command to open the Github URL. The equivalent command in OS X is open.

Opens wrong url for some repos

.git/config:

[remote "origin"]
  9   url = [email protected]:mojolingo/Telephony-Dev-Box.git
 10   fetch = +refs/heads/*:refs/remotes/origin/*

$ opengit then opens https://github.com/mojolingo/Telephony-Dev-Box%0Amojolingo/Telephony-Dev-Box

Open file

git-open /path/to/file

and have the browser open that file in the current branch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.